美文网首页
爬虫入门4(爬取小说)

爬虫入门4(爬取小说)

作者: 李玉奇_1aeb | 来源:发表于2019-02-12 19:13 被阅读0次

import requests
import re
import time
headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36"}
f=open(r"E:\python_document\斗破苍穹.txt","a+")
def get_info(url):
res=requests.get(url,headers=headers)
if res.status_code==200:
contents=re.findall("<p>(.*?)</p>",res.content.decode("utf-8"),re.S)
for content in contents:
f.write(content+"\n")
else:
pass

urls=['http://www.doupoxs.com/doupocangqiong/{}.html'.format(str(i)) for i in range(1,1647)]
for url in urls:
get_info(url)
time.sleep(1)
f.close()

相关文章

网友评论

      本文标题:爬虫入门4(爬取小说)

      本文链接:https://www.haomeiwen.com/subject/yiakeqtx.html