1 importre2 importurllib.request3 from bs4 importBeautifulSoup4 importtime5

6 url=input("第一页网址:")7

8 defgethtml(url):9 #获取页面源代码html

10 page=urllib.request.urlopen(url)11 html=page.read().decode('utf-8') #html是一个列表

12 soup=BeautifulSoup(html,'html.parser')13

14 returnsoup15

16

17 def getbookurl(soup): #获取该页所有书本的链接地址

18 try:19

20 firsturl2=[]21 bookurl=soup.find_all("h4")22 bookurl1=re.findall(r'

24 for i inrange(0,len(bookurl1)):25 bookurl="http:"+bookurl1[i]26

27

28 soup1=gethtml(bookurl) #获取每本书第一章 的url

29 time.sleep(0.2)30 firsturl=soup1.find_all("a",{"class":"red-btn J-getJumpUrl"})31 firsturl1=re.findall(r'data-firstchapterjumpurl=".*?" href="(.*?)" id="readBtn">',str(firsturl))32 if firsturl1[0]=='': #由于起点限制,某些链接无法爬取,显示的是一个空列表,这里要进行判断

33 continue

34 firsturl2.append(firsturl1[0])35 print(firsturl2)36 returnfirsturl237 except:38 returnfirsturl239

40

41

42

43 defgetcontent(soup,load):44

45 content=soup.find_all("div",{"class":"read-content j_readContent"})46

47 content1=re.compile(r'

([\s\S]*?)

')48

49 content2=content1.findall(str(content))50

51 content3=re.sub("?\w+[^>]*>",'',content2[0])52

53 content4=content3.replace('。','。\n\n\0\0\0') #到此,将章节内容获取完毕

54

55 contentname=re.compile(r'

(.*?)

')56

57 contentname1=contentname.findall(str(soup)) #获取章节名称

58

59 book="----------------------------------------------------------------"+contentname1[0]+"------------------------------------------------------------\n\n\n"+content460

61 with open(load, 'a',encoding='gb18030') as f: #这里的gb18030是GBK的父集,所以能兼容GBK不能编码的字符。

62

63 f.write(book)64

65

66

67 defnextcontent(soup):68

69 content=soup.find_all("div",{"class":"chapter-control dib-wrap"})70

71 #print(str(content))

72

73 step=re.compile(r'

75 content1=step.findall(str(content))76

77 if content1 ==[]:78

79 step1=re.compile(r'

81 content2=step1.findall(str(content))82

83 url="http:"+content2[0]84

85 returnurl86 else:87 url="http:"+content1[0]88

89 returnurl90

91 defpanduan(soup):92

93 content=soup.find_all("div",{"class":"chapter-control dib-wrap"})94

95 #print(str(content))

96

97 step=re.compile(r'

99 content1=step.findall(str(content))100

101 returncontent1102 #-------------------------------------------------------------------------

103

104

105

106 #-------------------------------------------------------------------------

107

108 while 1==1:109 soup2=gethtml(url)110 firsturl2=getbookurl(soup2)111

112 for j inrange(0,len(firsturl2)):113 url="http:"+firsturl2[j]114 soup1=gethtml("http:"+firsturl2[j])115 bookname=re.findall(r'

(.*?)

',str(soup1))116 load="d:/88/%s.txt" %bookname[0]117 i=0118 while 1==1:119 soup=gethtml(url)120 getcontent(soup,load)121 url=nextcontent(soup)122 content1=panduan(soup)123 i+=1

124 print("第%d章下载完成" %i)125

126 if content1 ==[]:127 break

128

129 time.sleep(0.2)130 print("-------------第%d本书下载完成---------" % int(j+1))131

python爬取起点vip小说章节_python 爬取qidian某一页全部小说相关推荐

  1. python爬取vip小说章节_python 爬取起点小说vip章节(失败)

    今天心血来潮,想爬取起点vip小说章节,花费了足足0.27大洋后,悟出来一个人生道理,这个应该是爬不下来.但是这0.27大洋也教会了我两个知识点. 1.服务器只会响应客户端的请求,不会主动给客户端发送 ...

  2. python爬取起点vip小说章节_python 爬取起点小说vip章节(失败)

    今天心血来潮,想爬取起点vip小说章节,花费了足足0.27大洋后,悟出来一个人生道理,这个应该是爬不下来.但是这0.27大洋也教会了我两个知识点. 1.服务器只会响应客户端的请求,不会主动给客户端发送 ...

  3. python使用fpdf生成pdf文件章节(chapter),包含:页眉、页脚、章节主题、数据排版等;

    python使用fpdf生成pdf文件章节(chapter),包含:页眉.页脚.章节主题.数据排版等: #仿真数据 The year 1866 was marked by a bizarre deve ...

  4. python 小说最新章节_python爬取笔趣阁小说(TK可视化)

    1 importrequests2 from lxml importetree3 from pyquery importPyQuery as pq4 importre5 importtime6 fro ...

  5. python爬取淘宝商品信息_python爬取淘宝商品信息并加入购物车

    先说一下最终要达到的效果:谷歌浏览器登陆淘宝后,运行python项目,将任意任意淘宝商品的链接传入,并手动选择商品属性,输出其价格与剩余库存,然后选择购买数,自动加入购物车. 在开始爬取淘宝链接之前, ...

  6. python可以爬取的内容有什么_Python爬取视频(其实是一篇福利)过程解析 Python爬虫可以爬取什么...

    如何用python爬取视频网站的数据 如何用python爬取js渲染加载的视频文件不是每个人都有资格说喜欢,也不是每个人都能选择伴你一生! 有哪位大神指导下,有些视频网站上的视频文件是通过 js 加载 ...

  7. Go爬取起点中文网 解决文字反爬

    Go语言的爬虫库不如Python强大,却也五脏俱全. 今天我们分析如何爬取起点中文网数据,以及遇到反爬如何处理. 作品链接:http://www.365yg.com/i6678092837810078 ...

  8. python爬取小说章节_python之如何爬取一篇小说的第一章内容

    现在网上有很多小说网站,但其实,有一些小说网站是没有自己的资源的,那么这些资源是从哪里来的呢?当然是"偷取"别人的数据咯.现在的问题就是,该怎么去爬取别人的资源呢,这里便从简单的开 ...

  9. python爬取小说网站_Python爬取小说网站下载小说

    1前言 这个小程序是用来爬取小说网站的小说的,一般的盗版小说网站都是很好爬取的 因为这种网站基本没有反爬虫机制的,所以可以直接爬取 该小程序以该网站http://www.126shu.com/15/下 ...

  10. Python分析并爬取起点中文网的章节数据,保存为txt文档

    如题,分析起点中文网,并提取出来章节链接,保存为txt文档. 代码仅供交流使用,请勿用作商业用途,如有违规,请联系删除 一,分析 1.打开带有章节的链接,例如:(随便选的一篇文章) 2.打开浏览器的抓 ...

最新文章

  1. 人脸识别争议不断 中美市场冰火两重天
  2. 用requests获取网页源代码 python-Python3使用requests包抓取并保存网页源码的方法
  3. 重磅 | 19 页花书精髓笔记!你可能正需要这份知识清单
  4. 编程之性能优化知多少
  5. java代理的学习,通过类实现接口来实现代理。proxy来创建动态类,和InvocationHandler接口的实现,和工作原理。...
  6. python简笔画怎么画_怎样用tk语句在Python下画一棵树
  7. 【数据库原理实验(openGauss)】 使用JDBC连接数据库
  8. Kd树实现K近邻算法
  9. 长沙优科软件开发有限公司招聘软件开发工程师
  10. java 蒙特卡洛_java算法3_蒙特卡洛方法(Monte Carlo method)求PI和椭圆面积
  11. python 读取最新阿里云RDS数据库备份并下载
  12. matlab 死区,MATLAB对AC/DC/AC电源的死区效应谐波仿真
  13. 手机APP如何远程控制PLC
  14. 语音识别 --- 音频信号提取
  15. 笔记2:VC++ socket通信实例
  16. 试题 算法训练 猴子分苹果
  17. Altium Designer PCB扇孔技巧
  18. JAVA三角海伦公式_(海伦公式)已知三角形三条边长,求面积
  19. linux安装文件多大空间,你的Linux系统上安装了多少内存?又使用了多少?
  20. AIQ - deeplearning.ai 全套吴恩达老师的深度学习课程笔记及资源在线

热门文章

  1. SUDOKU-数独游戏
  2. html5中图像水平边距,图像的垂直边距和水平边距属性
  3. codeforces 158B
  4. 算法系列之算法学习书籍以及资料推荐
  5. PHP 开源 ERP 系统 Discover
  6. 开放微博社区使用OAUTH协议简介
  7. html 中的版权符号 : 圆圈C
  8. 浅析:光纤跳线的插入损耗和回波损耗
  9. adobe 服务器当前无响应,浏览器假死无响应故障解决方法
  10. 计算机上面mac怎么查看,怎么看电脑的mac地址