当前位置:网站首页>三国演义章节内容
三国演义章节内容
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,'下载完成')
边栏推荐
- 电力电子:单项逆变器设计(MATLAB程序+AD原理图)
- Fasttext learning - text classification
- 【软件工程之美 - 专栏笔记】24 | 技术债务:是继续修修补补凑合着用,还是推翻重来?
- Hal learning notes - Basic timer of 7 timer
- STM32FF030 替代国产单片机——DP32G030
- 基于STC51:四轴飞控开源项目原理图与源码(入门级DIY)
- 智慧能源管理系统解决方案
- HAL学习笔记 - 7 定时器之基本定时器
- Huawei cloud 14 day Hongmeng device development -day1 source code acquisition
- HAL库学习笔记-11 I2C
猜你喜欢

Logistic regression - project practice - credit card detection task (Part 2)

arduino uno错误分析avrdude: stk500_recv(): programmer is not responding

Pytorch Basics (Introductory)

华为云14天鸿蒙设备开发-Day7WIFI功能开发

基于STC51:四轴飞控开源项目原理图与源码(入门级DIY)

智能货架安全监测系统

shell工具finalShell

【软件工程之美 - 专栏笔记】30 | 用好源代码管理工具,让你的协作更高效

2022春招——芯动科技FPGA岗技术面(一面心得)

防爆倾角传感器应用于LNG液化天然气安全作业
随机推荐
Huawei cloud 14 day Hongmeng device development -day5 drive subsystem development
markdown与Typora
从头安装MYSQL(MYSQL安装文档-解压版)
Fasttext learning - text classification
Transfer joint matching for unsupervised domain adaptation
Hal library learning notes - 8 use of serial communication
SimpleFOC调参2-速度、位置控制
Open source based on STM32: MHD Bluetooth speaker (including source code +pcb)
Ml8 self study notes LDA principle formula derivation
Power electronics: single inverter design (matlab program +ad schematic diagram)
TB6600+stm32F407测试
Pit avoidance: about the interconnection of two hc-05 master-slave integrated Bluetooth modules, there is no connection problem
STM32 串口乱码
TLE5012b+STM32F103C8T6(bluepill)读取角度数据
HAL库学习笔记- 8 串口通信之概念
【软件工程之美 - 专栏笔记】14 | 项目管理工具:一切管理问题,都应思考能否通过工具解决
Migration learning notes - adaptive component analysis
华为云14天鸿蒙设备开发-Day5驱动子系统开发
HAL库学习笔记-10 HAL库外设驱动框架概述
智慧充电桩系统由什么组成?