当前位置:网站首页>三国演义小说
三国演义小说
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,'下载完成')
边栏推荐
- shell中计算命令详解(expr、(())、 $[]、let、bc )
- Detailed explanation of calculation commands in shell (expr, (()), $[], let, bc )
- Jenkins--基础--5.4--系统配置--全局工具配置
- Flink 监控指南 被动拉取 Rest API
- ip地址那点事(二)
- 了解下C# 不安全代码
- Technology Cloud Report: To realize the metaverse, NVIDIA starts from building an infrastructure platform
- 积分商城商品供应商选择的三个要求
- 三维体尺测量
- day_05_pickel 和 json
猜你喜欢
RetinaFace: Single-stage Dense Face Localisation in the Wild
编程与哲学(2)——输出是为了更好的输入
uvm-phase机制
Three types of [OC learning notes] Block
类和对象【下】
如何做好项目管理
js函数防抖和函数节流及其使用场景
【Flink 问题】Flink 如何提交轻量jar包 依赖该如何存放 会遇到哪些问题
PostgreSQL learning summary (11) - PostgreSQL commonly used high-availability cluster solutions
工程师如何对待开源 --- 一个老工程师的肺腑之言
随机推荐
openpyxl 单元格合并
Seleniu screenshots code and assign name to the picture
day_05 time 模块
Hikari连接池源码解读
AI目标分割能力,无需绿幕即可实现快速视频抠图
houdini 求出曲线的法向 切线以及副法线
Jenkins--基础--07--Blue Ocean
pycharm的基本使用教程(1)
测试时大量TIME_WAIT
二分类和多分类
tf中tensor的大小输出
WebGPU 导入[1] - 入门常见问题与个人分享
location对象,navigator对象,history对象学习
Biotin-EDA|CAS:111790-37-5| Ethylenediamine biotin
Flink 系统性学习笔记系列
BGP solves routing black hole through MPLS
Technology Cloud Report: To realize the metaverse, NVIDIA starts from building an infrastructure platform
查看变量的数据格式
spark:页面单跳转换率统计(案例)
In a recent build figure SLAM, and locate the progress