在宿舍无聊时想做点小程序,刚好又看到笔趣阁的广告,就想着爬一下小说看看,通过网上的爬取教程整理的
使用beautifulsoup解析request获取的HTML http://beautifulsoup.readthedocs.io/zh_CN/latest/
# -*- coding:utf-8 -*-
import requests
from bs4 import BeautifulSoup
import os
if __name__=='__main__':
#所要爬取的小说主页,每次使用时,修改该网址即可,同时保证本地保存根路径存在即可
target="https://www.biqubao.com/book/17570/"
# 本地保存爬取的文本根路径
save_path = 'D:/pythontest/read'
#笔趣阁网站根路径
index_path='https://www.biqubao.com'
req=requests.get(url=target)
#查看request默认的编码,发现与网站response不符,改为网站使用的gdk
print(req.encoding)
req.encoding = 'gbk'
#解析html
soup=BeautifulSoup(req.text,"html.parser")
list_tag=soup.d