python 爬取整本小说到本地文件

headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"}
url = "https://www.quanben.net/274/274596/"
rps = requests.get(url,headers=headers)  # 获取url
rps.encoding = "utf-8"
#print(rps.text)2401
dom= etree.HTML(rps.text)
for i in dom.xpath('//*[@id="main"]/div[@class="inner"]'):
    for j in range(10,2402,1):
        #爬取目录
        picName0 = i.xpath("dl[@class='chapterlist']/dd["+str(j)+"]/a/text()")
        picurl=i.xpath("dl[@class='chapterlist']/dd["+str(j)+"]/a/@href")
        piculr1="https://www.quanben.net"+str(picurl).replace("['","").replace("']","")

        #爬取内容
        #https://www.quanben.net/274/274596/31096087.html
        print(picName0,str(piculr1))
        url = piculr1
        rps = requests.get(url, headers=headers)  # 获取url
        rps.encoding = "utf-8"
        # print(rps.text)2401
        dom = etree.HTML(rps.text)
        #//*[@id="BookText"]
        #for n in dom.xpath('//*[@id="BookText"]'):
        content=str(dom.xpath('//*[@id="BookText"]/text()')).replace("\xa0","")
        print(content)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值