python 小说下载_python下载小说
采用了requests库,代码修改一下文件存放的文章,以及添加一下小说目录就可以使用.
代码百度云# -*- coding: utf-8 -*-
"""
Created on Fri May 11 08:39:52 2018
@author: dflx
"""
import requests
import re
import time
import os
import requests.packages.urllib3.util.ssl_
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL'
import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()
def get_html(url):
header ={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.3.2.17331',
}
# 使用request库传参时不需要使用urlencode函数去编码成byte类型数据,库自动去编码。get方法参数是params=,post方法是data=
response = requests.get(url,headers = header,verify=False)
response.encoding=response.apparent_encoding
html=response.text
return html
def novel_information(html,reg):
novel_text=re.findall(reg,html)
#print(novel_text)
return novel_text
def get_regular_text(text):
global count
print("------get rgulax text----")
#print(type(text[0]),'length=',len(text))
new_word=text
if ' ' in text[0]:
new_word=re.sub(r' ',' ',text[0])
print(type(new_word),'length=',len(new_word))
if '
' in new_word:
new_word=re.sub(r'
','\n',new_word)
count+=len(new_word)
return new_word
def get_onechapter(url):
html = get_html(url)
re1 = r'
(.*?)
'
re2 = r'
'
novel_chapter_name = novel_information(html, re1)
text = novel_information(html, re2)
print("下载:------",count)
print(novel_chapter_name)
chapt_text=" "+novel_chapter_name[0]+'\n'+get_regular_text(text)
return chapt_text
def download_onechapter(words):
#下面是文件存目录,修改你的路径
path="/home/dflx/下载/novel/永夜君王.txt"
with open(path,'a+',encoding="utf-8") as f:
for word in words:
f.write(word)
f.write('\n')
def chapter_all(url,re3,host):
html=get_html(url)
#print(html)
chapter_list=novel_information(html,re3)
print("length=",len(chapter_list),type(chapter_list))
chapters=[host+ i for i in chapter_list]
chapters=[i+'.html' for i in chapters]
print(chapters)
#print(chapters.index("https://www.xxbiquge.com/68_68479/4010677.html"))
return chapters
def download_novel(url_all):
#for index in range(472,len(url_all)):
for chapt in url_all:
try:
words=get_onechapter(chapt)
download_onechapter(words)
except Exception:
continue
finally:
print("GOTO ANOTHER CHAPTER")
count=0;
def main():
host="https://www.xxbiquge.com"
#下面是小说目录界面,可以打开参考一下,修改成你需要的.
url0="https://www.xxbiquge.com/1_1797/"
re3=r'
start=time.clock();
try:
all=chapter_all(url0,re3,host)
download_novel(all)
except Exception as e:
print("has error"+str(e))
finally:
end=time.clock()
print("总计用时:%.2f s"%(end-start))
图片.png
python 小说下载_python下载小说相关推荐
- python 小说下载_Python下载网络小说实例代码
看网络小说一般会攒上一波,然后导入Kindle里面去看,但是攒的多了,机械的Ctrl+C和Ctrl+V实在是OUT,所以就出现了此文. 其实Python我也是小白,用它的目的主要是它强大文本处理能力和 ...
- 慕课python下载_python下载小说
下载新笔趣阁小说 采用了requests库,代码修改一下文件存放的文章,以及添加一下小说目录就可以使用. 代码百度云 # -*- coding: utf-8 -*- """ ...
- python爬虫小说教程_python制作小说爬虫实录
纪念我的第一个爬虫程序,一共写了三个白天,其中有两个上午没有看,中途遇到了各种奇怪的问题,伴随着他们的解决,对于一些基本的操作也弄清楚了.果然,对于这些东西的最号的学习方式,就是在使用中学习,通过解决 ...
- python编程图片_python下载百度图片,python图片下载程序
以前写的一个百度图片下载的代码,现在试试还能用,现在百度图片的质量也是越来越高了,共享一下,让粉丝和图片控能方便下载:后续功能追加请关注我的小站#coding:utf-8 ''' python 2.7 ...
- python 小说 云_Python给小说做词云
闲暇时间喜欢看小说,就想着给小说做词云,展示小说的主要内容.开发语言是Python,主要用到的库有wordcloud.jieba.scipy.代码很简单,首先用jieba.cut()函数做分词,生成以 ...
- python主题壁纸下载_Python 下载Bing壁纸
这个示例使用的Python版本为3.7版本, 一.bing壁纸接口 访问bing的官网,通过浏览器开发者工具,查看网络可以找到一个请求壁纸的接口,至于怎么判断的,我是发现当我把鼠标放在切换壁纸的左右箭 ...
- python主题壁纸下载_Python 下载Bing壁纸的示例
这个示例使用的Python版本为3.7版本, 一.bing壁纸接口 访问bing的官网,通过浏览器开发者工具,查看网络可以找到一个请求壁纸的接口,至于怎么判断的,我是发现当我把鼠标放在切换壁纸的左右箭 ...
- 看漫画学python下载_Python下载漫画
上午起来提不起劲,于是就用电脑看漫画,但是在线看漫画好烦,就想下下来看.一个一个点太麻烦,于是花了点时间用python写了个demo,把爱漫画的漫画下载下来,这样就可以随时随地看了.这也是我首次尝试用 ...
- python sftp模块_python下载paramiko模块准备使用SFTP的坑!!!
python版本3.7 因为不交代自己版本都是不讲码德.... pip install paramiko 报错!!! running build_ext generating cffi module ...
最新文章
- ios wallet开发_iOS: 使用UICollectionView实现Wallet效果
- 单链表问题(反转、是否有环、删除结尾第N个节点、合并两个sortlist、找到交点)
- 软件工程--项目开发计划
- 盘点2015年前20款表现出色的免费开源软件
- mysql 5.6.27安装图解_Linux下MySQL 5.6.27 安装教程
- C/C++ 常量的定义与应用(编程中的常量)
- 【SKILLS】拯救你的----连读
- 阿里专家:怎么样消除程序员的中年危机?
- Ajax异步请求阻塞情况的解决办法(asp.net MVC Session锁的问题)
- Android开机动画没有声音,Android O 8.0 自定义开机动画/开机铃声
- RecyclerView 删除元素后,点击报 IndexOutOfBoundsException 解决方法
- USYD悉尼大学INFO1110 详细作业解析Week4 revision(未更新完)
- dota自走棋设置上海服务器位置,Dota2自走棋怎么设置国服 让你轻松进入国服
- 高尔顿钉板实验是二项分布吗?
- 谷歌开源 ClusterFuzz,自动化查找并修复 bug
- 『迷你教程』机器学习的Bootstrap及Python实现
- 红帽 Linux 考试 要求
- 【12-06】A股主要指数的市盈率(PE)估值高度
- 认清影响因子引发的是是非非,善待逆境中顽强崛起的国产期刊
- Vue 组件传值通信、父子组件、爷孙组件传值、方法调用