Calibre 3.38.1 下载 Runoob 网站中的《Python 2 教程》的 Recipe

代码如下:

 1 #!/usr/bin/env python2
 2 # vim:fileencoding=utf-8
 3 from __future__ import unicode_literals, division, absolute_import, print_function
 4 from calibre.web.feeds.news import BasicNewsRecipe
 5 
 6 class AdvancedUserRecipe1547983886(BasicNewsRecipe):    # 继承 BasicNewsRecipe 类的新类名
 7     #/
 8     # 设置电子书元数据
 9     #/
10     title = 'Runoob Python 2 教程'    # 电子书名
11     description = 'Python是一种解释型、面向对象、动态数据类型的高级程序设计语言。Python由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。像Perl语言一样, Python 源代码同样遵循 GPL(GNU General Public License)协议。本教程主要针对Python 2.x版本的学习,如果你使用的是Python 3.x版本请移步至Python 3.X版本的教程。'    # 电子书简介
12     cover_url = 'http://www.runoob.com/wp-content/uploads/2013/11/python.jpg'    # 电子书封面
13     # masthead_url    = ''    # 页头图片
14     __author__ = 'Runoob'    # 作者
15     language = 'zh'        # 语言
16     encoding = 'utf-8'    # 编码
17     #/
18     # 抓取页面内容设置
19     #/
20     #keep_only_tags    = [{ 'class': 'example' }] # 仅保留指定选择器包含的内容
21     no_stylesheets = True    # 去除 CSS 样式
22     remove_javascript = True    # 去除 JavaScript 脚本
23     # oldest_article    = 7
24     max_articles_per_feed = 999    # 抓取文章数量
25     delay = 5        # 抓取资源间隔时间
26     auto_cleanup = True
27     #/
28     # 页面内容解析方法
29     #/
30     def parse_index(self):
31         site = 'http://www.runoob.com/python/python-tutorial.html'    # 页面列表页
32         soup = self.index_to_soup(site)        # 解析列表返回 BeautifulSoup 对象
33         links = soup.findAll('a', {'target': '_top'})    # 获取所有文章的链接地址
34         articles = []    # 定义文章资源数组
35         for link in links:    # 循环处理所有文章链接
36             title = link.contents[0].strip()    # 提取文章标题
37             print(title)
38             print(link)
39             url = site + link['href']        # 提取文章链接
40             print(u'%s'%(url))
41             a ={'title':title,'url':url}        # 组合标题和链接
42             articles.append(a)    # 累加到数组中
43         ans = [(self.title,articles)]    # 组成最终的数据结构
44         return ans    # 返回可供 Calibre 转换的数据结构   

 

转载于:https://www.cnblogs.com/mcgill0217/p/10296052.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值