全书网

本文介绍了一个使用Python爬虫从全书网抓取小说目录的示例代码,通过解析网页获取小说标题、链接及阅读入口,进一步获取书籍的章节目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import requests
import re
from lxml import etree
start_url ='http://www.quanshuwang.com/list/5_{}.html'
book_page=1
# 1到128页书的网址
for book_page in range(1):
url =start_url.format(book_page)
response =requests.get(url).content.decode('gbk')
# print(response)
book_html= ' <li><a target="_blank" href="(.*?)" class="l mr10">'

# book_title ='alt="(.*?)"'
book_title ='<a target="_blank" title="(.*?)" '
re_html= re.findall(book_html,response)
re_title =re.findall(book_title,response)
# for title,html in zip(re_title,re_html):
# print(title,html)

#range(1,20)书的数量,1到20的书籍数量
for j in range(1,20):

response_book =requests.get(re_html[j]).content.decode('gbk')
read_start=' <a href="(.*?)" class="reader" title="(.*?)">开始阅读</a>'
read_menu=re.findall(read_start,response_book)
print(read_menu[0][0])
print(read_menu[0][1])
menu_url =requests.get(read_menu[0][0]).content.decode('gbk')
print(menu_url)
book_mulu='<DIV class="dirtitone"><H2>(.*?)</H2></div>'
print(re.findall(book_mulu,menu_url))

转载于:https://www.cnblogs.com/LQ970811/p/10508680.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值