scrapy_novel_python

Posted Edge of Eternity

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scrapy_novel_python相关的知识,希望对你有一定的参考价值。

 1 # _*_ coding:UTF _8_
 2 from bs4 import BeautifulSoup
 3 import requests,sys
 4 class downloader(object):
 5     def __init__(self):
 6         self.server = http://www.biqukan.com/
 7         self.target = http://www.biqukan.com//1_1094/
 8         self.names = []
 9         self.urls = []
10         self.nums = 0
11     #获取下载链接
12     def get_download_url(self):
13         reg = requests.get(url = self.target)
14         html = reg.text
15         div_bf = BeautifulSoup(html)
16         div = div_bf.find_all(div, class_ = listmain)
17         a_bf = BeautifulSoup(str(div[0]))
18         a = a_bf.find_all(a)
19         self.nums = len(a[15:])
20         for each in a[15:]:
21             self.names.append(each.string)
22             self.urls.append(self.server + each.get(href))
23     #获取章节内容
24     def get_contents(self,target):
25         req = requests.get(url = target)
26         html = req.text
27         bf = BeautifulSoup(html)
28         texts = bf.find_all(div,class_ = showtxt)
29         texts = texts[0].text.replace(\xa0*8,\n\n)
30         return texts
31     #写入文件
32     def writer(self,name,path,text):
33         write_flag = True
34         with open(path,a,encoding=utf-8) as f:
35             f.write(name + \n)
36             f.writelines(text)
37             f.write(\n\n)
38 if __name__ == __main__:
39     dl = downloader()
40     dl.get_download_url()
41     print(《一念永恒》开始下载:)
42     for i in range(dl.nums):
43         dl.writer(dl.names[i],一念永恒.txt,dl.get_contents(dl.urls[i]))
44         sys.stdout.write("已下载:%.3f%%" % float(i/dl.nums) + \r)
45         sys.stdout.flush()
46     print(《一念永恒》下载完成)

 

以上是关于scrapy_novel_python的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——CSS选择器

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数