当前位置:网站首页>三国演义小说
三国演义小说
2022-08-02 08:35:00 【赵颂@】
import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
#爬取三国演义小说所有章节标题和章节内容 https://www.shicimingju.com/book/sanguoyanyi.html
if __name__ =='__main__':
headers={
"User-Agent":UserAgent().chrome
}
get_url='https://www.shicimingju.com/book/sanguoyanyi.html'
#发起请求,获取响应
page_text=requests.get(url=get_url,headers=headers).text.encode('ISO-8859-1')
#在首页中解析出章节标题和章节内容
#1. 实例化BeautifulSoup对象,将html数据加载到该对象中
soup=BeautifulSoup(page_text,'lxml')
# print(soup)
#2.解析章节标题和详情页的url
list_data=soup.select('.book-mulu > ul > li')
fp=open('./sanguo.text','w',encoding='utf-8')
for i in list_data:
title=i.a.text
detail_url='https://www.shicimingju.com/'+ i.a['href']
#对详情页的url发送请求,
detail_text=requests.get(url=detail_url,headers=headers).text.encode('ISO-8859-1')
detail_soup=BeautifulSoup(detail_text,'lxml')
#获取章节内容
content=detail_soup.find('div',class_='chapter_content').text
#持久化存储
fp.write(title+":"+content+"\n")
print(title,'下载完成')
边栏推荐
猜你喜欢
MySQL Workbench 安装及使用
Redisson的看门狗机制
C语言_指针
USACO美国信息学奥赛竞赛12月份开赛,中国学生备赛指南
Postman download localization of installation and use
向量组的线性相关性
PyQt5 (a) PyQt5 installation and configuration, read from the folder and display images, simulation to generate the sketch image
C语言基础_共用体
houdini 求出曲线的法向 切线以及副法线
如何建立私域流量?私域流量对企业有什么好处?
随机推荐
Wang Xuegang - compiled shipment line file
uvm-phase机制
自定义View实现波浪荡漾效果
tf.where使用
下一个排列
第3周学习:ResNet+ResNeXt
普林斯顿微积分读本03第二章--编程实现函数图像绘制、三角学回顾
【开源项目】X-TRACK源码分析
Three types of [OC learning notes] Block
如何建立私域流量?私域流量对企业有什么好处?
Fiddler(七) - Composer(组合器)克隆或者修改请求
PyQt5(一) PyQt5安装及配置,从文件夹读取图片并显示,模拟生成素描图像
R language plotly visualization: plotly visualizes the scatter plot of the actual value of the regression model and the predicted value of the regression, analyzes the prediction performance of the re
Spark 系统性学习笔记系列
Pycharm (1) the basic use of tutorial
A little bit of knowledge - why do not usually cook with copper pots
Mysql Mac版下载安装教程
spark:热门品类中每个品类活跃的SessionID统计TOP10(案例)
EPSANet: An Efficient Pyramid Split Attention Block on Convolutional Neural Network
Seleniu screenshots code and assign name to the picture