很开心,自己用Python爬小说看!
import urllib.request
from bs4 import BeautifulSoup
i =253
while i<=369:
url = "https://www.hkslg.net/303/303208/63385"+str(i)+".html"
#print (url)
content = urllib.request.urlopen(url).read()
soup = BeautifulSoup(content,"html.parser")#html.parser
fo = open("C:/Users/Administrator/Desktop/yh3.txt", "ab+") #打开小说文件
# 以二进制写入章节内容
fo.write((soup.p).encode('UTF-8'))
fo.close() #关闭小说文件
i=i+1
print (i)
虽然很简单,但是比较有感觉。
要自信!要自信!要自信!要自信!要自信!要自信!
20190706
print("666")
import urllib.request
from bs4 import BeautifulSoup
i =163
while i<=763:
url = "https://www.yangguiweihuo.com/10/10868/5978"+str(i)+".html"
#print (url)
contents = urllib.request.urlopen(url).read()
soup = BeautifulSoup(contents,"html.parser")#html.parser
fo = open("C:/Users/Administrator/Desktop/jys1.txt", "ab+") #打开小说文件
# 以二进制写入章节内容
#print (soup.h1.text)
fo.write(soup.h1.text.encode())
for k in soup.find_all('div',class_='showtxt'):#,string='更多'
#print(k.text)
date = k.text.replace("https://www.yangguiweihuo.com/10/10868/5978", "\n ")
date = date.replace(str(i), "\n ")
date = date.replace(".htmlchaptererror();请记住本书首发域名:www.yangguiweihuo.com。笔趣阁手机版阅读网址:m.yangguiweihuo.com", "\n ")
fo.write(date.encode())
fo.close() #关闭小说文件
i=i+1
print (i)