python 小说下载_通过python自动获取小说并下载
1 importurllib.request2 importos3
4 headers ={5 "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163"
6 "Safari/535.1",7 }8
9
10 #主程序,获取每个章节的名称及链接
11 defmain():12 print('开始下载')13 url_list =[]14 url = 'http://www.eywedu.com/honglou/01/index.htm'
15 res = urllib.request.Request(url, data=None, headers=headers)16 html = urllib.request.urlopen(res).read().decode('gb18030')17 lists = html.split('')34 get_content(net+cut[0], cut[1])35 print('第', page, '章已下完')36 page = page+1
37
38
39 #根据每章链接获得内容
40 defget_content(url, name):41 paragraphs =[]42 res = urllib.request.Request(url, data=None, headers=headers)43 html = urllib.request.urlopen(res).read().decode('gb18030')44 lists = html.split('
')45 t =046 while t
')[1]49 p = p.replace('\r\n', '')50 paragraphs.append(p)51 elif t == len(lists) - 1:52 p = lists[t].split(r'')[0]53 p = p.replace('\r\n', '')54 paragraphs.append(p)55 else:56 p = lists[t].replace('\r\n', '')57 paragraphs.append(p)58 t = t + 1
59 save_txt(paragraphs, name)60
61
62 #将得到的信息保存
63 defsave_txt(content, name):64 f = open('红楼梦\\'+name+'.txt', "a", encoding='utf-8')65 for i incontent:66 f.write(i)67 f.close()68
69
70 if __name__ == '__main__':71 main()
python 小说下载_通过python自动获取小说并下载相关推荐
- python爬虫小说代码示例-Python从零开始写爬虫-4 解析HTML获取小说正文
Python从零开始写爬虫-4 解析HTML获取小说正文 在上一节中, 我们已经学会如何获取小说的目录, 这一节我们将学习如何通过正则表达式(在第二节学习过)来获取小说正文. 首先, 先随便选择一个章 ...
- python 时间序列预测_使用Python进行动手时间序列预测
python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...
- python 概率分布模型_使用python的概率模型进行公司估值
python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...
- python 小说爬虫_用Python爬虫下载整本小说
1 / 写在前面的话 / 如今网络上很多小说网站都有免费的小说阅读,但是它不提供下载全本的服务,目的也是为了获得更多的流量,资源君就不服了,今天刚好看到一个小说网站,就想弄本小说来看看,于是拿起电脑, ...
- spotify音乐下载_使用Python和R对音乐进行聚类以在Spotify上创建播放列表。
spotify音乐下载 Spotify is one of the most famous Music Platforms to discover new music. The company use ...
- python虚拟机下载_虚拟机 python
广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 打开文件--打开bashrc--加入#addexportvirtualenvwr ...
- python操作微信手机端下载_【python】自动化连接和操作手机微信
1. 环境配置 JDK Android SDK Appium MuMu 1.1. JDK 1.1.1. 下载安装 去华为云镜像下载JDK,我下载的版本是:jdk-8u181-windows-x64.e ...
- python urlretrieve登录下载_使用python urlretrieve下载文件
urlretrieve()方法直接将远程数据下载到本地.urlretrieve()是python urllib下的一个函数,python3已经将urlretrieve()移到urllib.reques ...
- python爬小说目录_【python入门爬虫】爬取笔趣阁小说
[Python] 纯文本查看 复制代码import time from bs4 import BeautifulSoup import requests import urllib.parse #模拟 ...
- 系统架构设计师与系统分析师历年实体分析与解答下载_做Python数据分析5年了,复制粘贴是我最牛逼的技能,直到看到这些公众号,我学习了...
上次跟一个学妹聊天,问她平时怎么学习,她反手甩给我这几个公众号,说很喜欢里面的技术文章,推荐给大家 深度学习这件小事 机器学习,深度学习,自然语言处理,计算机视觉--这些小事情,只要你主动,我们就有可 ...
最新文章
- oracle 10g数据库的异步提交
- c语言字符串67ASDSff,(指针编程题目.doc
- NYOJ 269 VF
- Qt Creator 最实用的快捷操作
- 【SICP练习】3 练习1.7
- 背不下《道德经》,至少背下这10句精华!
- 微课--Python网络爬虫采集百度搜索结果(例4-5)
- css 判断 移动设备 横屏 或 竖屏
- 基于相关向量机RVM的分类算法
- 十、Oracle学习笔记:基本查询语句各子句用法
- python可视化拖拽编程平台_PythonEditor可视化拼插编辑器:编程不用写代码,拖拖拽拽就可以!...
- Android中ListActivity的使用和在ListView中添加图片文字
- 苹果手机投屏电脑win7
- 弱监督学习-snorkel
- Python:保存文件npy格式
- 没有心的男人 2012-02-08 21:11:06
- 学计算机Java和c语言哪个出路比较好
- 2020年中国各省GDP简析
- 没有授权,Android App 也能获取你的权限?!
- java读取文件的字节数据