import requests
from lxml import etree
import time
url="https://www.85xscc.com/book/doupocangqiong/13495.html"
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"}
while 1:
try:
resp=requests.get(url,headers=headers)
except:
print("未知异常")
time.sleep(1)
continue
resp.encoding="utf-8"
e=etree.HTML(resp.text)
info="\n".join(e.xpath('//div[@class="m-post"]/p/text()'))
title=e.xpath('//h1/text()')[0]
with open("斗破苍穹.txt", "a", encoding='utf-8') as f:
f.write(title+"\n\n"+info+"\n\n")
url=f"https://www.85xs.cc{e.xpath('//tr/td[2]/a/@href')[0]}"
time.sleep(1)
print(title)
标签:xpath,title,url,text,resp,headers,小说,下载 From: https://www.cnblogs.com/jzm123/p/17292494.html