当前位置:首页 > 技术手札 > 正文内容

carlibre抓取网页内容生成电子书

秋风渡红尘8年前 (2018-06-27)技术手札2860
#!/usr/bin/python
# encoding: utf-8
from calibre.web.feeds.recipes import BasicNewsRecipe
class Pro_Git_Chinese(BasicNewsRecipe):

    title = 'QCustomplot'
    description = 'QCustomplot介绍'
    cover_url = ''
    _author_ = '朝十晚八'

    url_pre = 'https://www.cnblogs.com/swarmbees/category/908110.html'
    no_stylesheets = True #去除css
    keep_only_tags = [{ 'class': 'blogpost-body' }] #仅在blogpost-body里面查找
    simultaneous_downloads = 1 #最大下载线程,默认为5

    def parse_index(self):
# recipe的核心method,通过分析目录页,找到各页面链接,并抓取内容,返回一个较复杂的数据结构
        soup = self.index_to_soup(self.url_pre)#目录页
	#查找div,其class属性为entrylist,因为列表是处于<div class="entrylist">容器中
        div = soup.find('div', {'class': 'entrylist'})#目录页的寻找范围

        articles = []
        for link in div.findAll('a', id=True):#循环查找标签a,且其id要为真。
            til = link.contents[0].strip() #获取标题,去除空格
            url = link['href'] #获取标题的链接
            a = { 'title': til, 'url': url }
            articles.insert(0,a) #append(a)是在列表末尾追加,现在改成insert(0,a)在列表前面插入
        results = [(self.title, articles)] #结果由标题和文章组成
        return results

--------------------------------------------------------------------------------------------------------------------


#!/usr/bin/python
# encoding: utf-8
from calibre.web.feeds.recipes import BasicNewsRecipe
class Pro_Git_Chinese(BasicNewsRecipe):

    title = 'QT学习之路2'
    description = ''
    __author__ = '豆子'
    cover_url = ''
    simultaneous_downloads = 5

    url_pre = 'https://www.devbean.net/2012/08/qt-study-road-2-catelog/'
    no_stylesheets = True
    remove_javascript = True
    keep_only_tags = [{ 'class': 'thecontent clearfix' }]

    def parse_index(self):
# recipe的核心method,通过分析目录页,找到各页面链接,并抓取内容,返回一个较复杂的数据结构
        soup = self.index_to_soup(self.url_pre)#目录页

        div = soup.find('ol')#目录页的寻找范围
	
        articles = []
        for link in div.findAll('a'):
            til = link.contents[0].strip()
            url = link['href']
            a = { 'title': til, 'url': url}

            articles.append(a)

        results = [(self.title, articles)]

        return results


扫描二维码推送至手机访问。

版权声明:本文由咿呀贝发布,如需转载请注明出处。

本文链接:https://yiyabei.cn/?id=22

标签: calibre
分享给朋友:

相关文章

工作站T7810重装系统注意事项

工作站T7810重装系统注意事项

        dell的工作站T7810(Dell Precision Tower 7810)由于使用了磁盘阵列技术,在重装系统时发现会找不到任何驱动设备。...

如何禁用Firefox火狐浏览器的“不安全密码警告”

如何禁用Firefox火狐浏览器的“不安全密码警告”

Step1: 打开firefox,在地址栏敲:about:config 此时会跳出:“这可能是质量保证失效”的页面,点击“我了解此风险” Step2: 在配置页面的顶部搜索栏里敲:...

AUTO CAD2018启动出现Unhandled……

AUTO CAD2018启动出现Unhandled……

AUTO CAD2018启动出现Unhandled…… 回想起之前正常启动之后动过电脑的情况,一是安装了第二个显示器并更新了驱动。二是安装skecthup2017时为了安装netframework4.5.2不得已卸载了4....

ubuntu把iso镜像文件添加为更新源

ubuntu把iso镜像文件添加为更新源

环境:vmware12 + win7物理机 + ubuntu16.04虚拟机 iso是用vm直接挂载到ubuntu的,其实是想用iso来升级系统,结果不知道怎么执行升级,反而是一大堆问题。 正确添加源的方法是:...

cocos creator逐个输出字体实现方式

cocos creator逐个输出字体实现方式

方法一: for str += string 特点是每次循环前面的字符都要重新输出一次,容易造成闪烁。 方法二: for location[i].t...

cocos creator 学习总结

cocos creator 学习总结

文章来自https://blog.csdn.net/xiayuhoune/article/details/78824841 仅供自学参考。 一、基本内容: 1.cc.Label相关: (1)动态创建...