1 Star 0 Fork 185

chengshun16 / Python爬虫

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
爬取笔趣阁小说(1.0).py 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
import requests
from pyquery import PyQuery as pq
import re
print('*'*40)
print('*此程序针对笔趣阁小说网站设计的 ')
print('*网站的URL:https://www.qu.la/ ')
print('*此程序为1.0版本 代码写的很烂 后期优化代码和速度')
print('*'*40)
url='https://www.qu.la/book/3775/'
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0'
}
html_info=requests.get(url=url,headers=headers).text
#print(html_info)
doc=pq(html_info)
items=doc('.box_con #list').items()
test=[]
#print(html_info)
io=0
for i in items:
a=doc('a').items()
for u in a:
uy=u.attr('href')
p=re.compile('/book/3775/.*?\.html',re.S).findall(uy)
for u in p:
b='https://www.qu.la/book/'+u
#print(b)
cu=requests.get(url=b).text
#print(cu)
doc=pq(cu)
#获取小说章节
#it=doc('.bookname h1')
#获取小说内容
ite=doc('#content')
#c=it.text()
#tu=c+'.txt'
d=ite.text()
#print(tu)
with open('F:/小说/第%s章.txt'%io,'w')as p:
p.write(d)
print('当前已爬取%s章节了 请您耐心等待'%io)
io+=1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chengshun16/python_reptilian.git
git@gitee.com:chengshun16/python_reptilian.git
chengshun16
python_reptilian
Python爬虫
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891