爬取起点免费小说

**(爬取起点免费小说)
爬取的小说:在这里插入图片描述
代码:
import requests
from lxml import etree
headers = {
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36’
}
response = requests.get(“https://book.qidian.com/info/1013432619”).text
html = etree.HTML(response)
link = html.xpath(’//ul[@class=“cf”]/li/a/@href’)
temp = []
for i in link:
start_url = “https:”
new_url = start_url + i
temp.append(new_url)

for a in temp:
response = requests.get(a, headers=headers).text
html = etree.HTML(response)
chapter_name = html.xpath(’//div[@class=“text-head”]/h3/text()’)
content = html.xpath(’//div[@class=“read-content j_readContent”]/p/text()’)
chapter_names = “”.join(chapter_name)
conn = “”.join(content).replace("\u3000", “”)
# print(chapter_name, conn)
with open(‘d:\m.txt’, ‘a’, encoding=“utf-8”)as f:
f.write(chapter_names)
f.write(’\n\n’)
f.write(conn)

结果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值