当前位置:网站首页>三国演义章节内容
三国演义章节内容
2022-07-29 05:23: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,'下载完成')
边栏推荐
- 倾角传感器用于通信铁塔、高压电塔长期监测
- Transformer review + understanding
- HAL库学习笔记-14 ADC和DAC
- How to use the pre training language model
- HAL库学习笔记- 8 串口通信之使用
- 电力电子:单项逆变器设计(MATLAB程序+AD原理图)
- Migration learning - geodesic flow kernel for unsupervised domain adaptation
- Dust and noise monitoring system
- 防爆倾角传感器应用于LNG液化天然气安全作业
- 2022春招——芯动科技FPGA岗技术面(一面心得)
猜你喜欢

Migration learning - geodesic flow kernel for unsupervised domain adaptation

华为云14天鸿蒙设备开发-Day1环境搭建

给二维表添加时间序列索引

ArduinoIDE + STM32Link烧录调试

Hal learning notes - Basic timer of 7 timer

基于AD9850的多功能信号发生器

Based on stc51: schematic diagram and source code of four axis flight control open source project (entry-level DIY)

传统模型预测控制轨迹跟踪——圆形轨迹(功能包已经更新)

STM32 串口乱码

FPGA based: multi-target motion detection (hand-in-hand teaching ①)
随机推荐
HAL库学习笔记- 9 DMA
STM32: mcnamu wheel tracking task (library function program code)
【RoboMaster】A板接收JY-ME01角度传感器数据--modebus协议&CRC软件校验
Hal library learning notes-14 ADC and DAC
传统模型预测控制轨迹跟踪——波浪形轨迹(功能包已经更新)
From entry to soul: how to use tb6600 single chip microcomputer to control stepping motor with high precision (42/57)
基于STM32:情侣互动玩偶(设计方案+源码+3D图纸+AD电路)
Hal library learning notes - 8 use of serial communication
新能源充电桩后台管理系统平台
新能源共享充电桩管理运营平台
Torch. NN. Embedding() details
基于51单片机的四路抢答器仿真
How to use the pre training language model
CS4344国产替代DP4344 192K 双通道 24 位 DA 转换器
华为云14天鸿蒙设备开发-Day7WIFI功能开发
基于51单片机ADC0808的proteus仿真
Huawei cloud 14 day Hongmeng device development -day3 kernel development
Design and implementation of QT learning notes data management system
Migration learning - geodesic flow kernel for unsupervised domain adaptation
HAL学习笔记 - 7 定时器之基本定时器