当前位置:网站首页>三国演义小说
三国演义小说
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,'下载完成')
边栏推荐
- 为什么都推荐使用wordpress, 而不是 phpcms 这些国内的CMS呢?
- 十大免费cms建站系统介绍推荐
- ORBSLAM代码阅读
- RetinaFace: Single-stage Dense Face Localisation in the Wild
- Technology Cloud Report: To realize the metaverse, NVIDIA starts from building an infrastructure platform
- C语言_条件编译
- 【特别提醒】订阅此专栏的用户请先阅读本文再决定是否需要购买此专栏
- 大厂外包,值得拥有吗?
- C Language Basics_Union
- PyQt5(一) PyQt5安装及配置,从文件夹读取图片并显示,模拟生成素描图像
猜你喜欢
随机推荐
What attributes and methods are available for page directives in JSP pages?
js函数防抖和函数节流及其使用场景
那些年我们踩过的 Flink 坑系列
利用minlm比较句子之间的相似度
下一个排列
C语言基础_共用体
next permutation
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之一:解题思路
mysql 中 in 的用法
[OC学习笔记]weak的实现原理
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
oracle的sql改成mysql版本
如何做好项目管理
四字节的float比八字结的long范围大???
PyQt5(一) PyQt5安装及配置,从文件夹读取图片并显示,模拟生成素描图像
Technology Cloud Report: To realize the metaverse, NVIDIA starts from building an infrastructure platform
cas: 139504-50-0 Maytansine DM1|Mertansine|
LeetCode_2357_使数组种所有元素都等于零
Redisson的看门狗机制
Biotin-C6-amine|N-biotinyl-1,6-hexanediamine|CAS: 65953-56-2









