今天写一个脚本
获取笔趣看小说的代码
输入链接即可扒光一部小说并且保存
该站任意一部小说都可以
公众号回复 笔趣看 获取源代码
首先打开网站
随便点击一部小说
然后可以看到所有的章节
所以
思路:
1、获取小说首页源代码
2、提取所有章节链接
3、访问所有章节链接
4、提取内容 保存
访问网站,获取源代码
用bs4来解析提取数据
response = requests.get(url=url,headers=headers)
text = response.text
soup = BeautifulSoup(text,'html.parser')
# 找到所有的章节链接
lis = soup.find_all('ul',class_='p2')[1].find_all_next('li')
再用for循环去一个一个提取
for li in lis:
# 提取章节链接 和 章节名称
href1 = li.find_next('a').get('href')
href2 = href1.replace('.html','')
title = li.find_next('a').get('title')
由于url地址特殊
所以做了点改动
然后提取章节内容
最后做点装饰
效果
没问题
本段代码任意一部小说都可适用
可以扒光该站任意一部小说
记住要适可而止啊
公众号回复 笔趣看获取源代码
代码仅供学习参考
感谢观看!