当前位置:网站首页>三国演义章节内容
三国演义章节内容
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,'下载完成')
边栏推荐
猜你喜欢

充电桩充电技术新能源充电桩开发

【软件工程之美 - 专栏笔记】17 | 需求分析到底要分析什么?怎么分析?

智能货架安全监测系统

Huawei cloud 14 day Hongmeng device development -day7wifi function development

物联网倾斜监测解决方案

【软件工程之美 - 专栏笔记】24 | 技术债务:是继续修修补补凑合着用,还是推翻重来?

华为云14天鸿蒙设备开发-Day3内核开发

倾角传感器用于通信铁塔、高压电塔长期监测

Hal learning notes - Basic timer of 7 timer

Reading papers on false news detection (5): a semi supervised learning method for fake news detection in social media
随机推荐
给二维表添加时间序列索引
智慧能源管理系统解决方案
基于wifi的温度采集与控制系统
Transformer review + understanding
Huawei cloud 14 day Hongmeng device development -day3 kernel development
Design and implementation of QT learning notes data management system
简洁代码实现pdf转word文档
基于FPGA:运动目标检测(原理图+源码+硬件选择,可用毕设)
新能源充电桩后台管理系统平台
2022 spring recruit - Hesai technology FPGA technology post (one or two sides, collected from: Digital IC workers and FPGA Explorers)
FT232替代GP232RL USB-RS232转换器芯片国产化应用
CV520国产替代Ci521 13.56MHz 非接触式读写器芯片
兼容cc1101/cmt2300-DP4301 SUB-1G 无线收发芯片
DP1332E 多协议高度集成非接触式读写芯片
【软件工程之美 - 专栏笔记】17 | 需求分析到底要分析什么?怎么分析?
HAL库学习笔记-11 I2C
Hal learning notes - Basic timer of 7 timer
Ml4 self study notes
Power electronics: single inverter design (matlab program +ad schematic diagram)
PHY6252是一款超低功耗物联网蓝牙无线通信芯片