You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
python-project/spider/小说.py

16 lines
534 B

import requests
from lxml import etree
import time
next_url = "http://book.zongheng.com/chapter/1128608/66171932.html"
for i in range(1,100):
html = requests.get(url=next_url)
e = etree.HTML(html.content)
title = e.xpath('//div[@class="title_txtbox"]/text()')[0]
text = '\n'.join(e.xpath('//p/text()'))
next_url = e.xpath('//div/a[text()="下一章"]/@href')[0]
with open(f'国公凶猛.txt','a') as f:
f.write(title+'\n')
f.writelines(text)
print(title,'下载成功')
time.sleep(0.5)