diff --git a/AI/AIFunctionSe b/AI/AIFunctionSe new file mode 100644 index 0000000000000000000000000000000000000000..e99bf9d806c18e59207bedc64ac0843b1baeb53f --- /dev/null +++ b/AI/AIFunctionSe @@ -0,0 +1,21 @@ +import requests +from lxml import etree + +url = 'https://book.zongheng.com/showchapter/1284449.html' +headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/120.0.0.0 Safari/537.36'} +rq = requests.get(url=url, headers=headers) +rq.encoding = 'utf-8' +data = etree.HTML(rq.text) +titles = data.xpath('//ul[@class="chapter-list"]/li/a/text()') +chapter_urls = data.xpath('//ul[@class="chapter-list"]/li/a/@href') + +for title, chapter_url in zip(titles, chapter_urls): + rq1 = requests.get(url=chapter_url, headers=headers) + data1 = etree.HTML(rq1.text) + content = data1.xpath('//*[@id="Jcontent"]/div/div[4]/p/text()') + text = '\n'.join(content) + + print(f"正在爬取章节:{title}") + + with open(f'E:\\gyy\\novel\\{title}.txt', 'w', encoding='utf-8') as f: + f.write(text) \ No newline at end of file