calibre recipe制作-puashu.com的recipe示例
来源:互联网 发布:丽水学院网络教学平台 编辑:程序博客网 时间:2024/05/22 15:48
本来想要看《沟通的艺术》这本书,网上找不到合适的电子版本(支持kindle的)。所以只好用puashua.com的电子书,唯一不好的就是没有图片。
puashu.com的制作电子书思路
查阅calibre提供的API请看下面的推荐阅读
电子书首页解析
在制作recipe中,因为puashu没有提供RSS服务,所以我们需要自己解析首页。即提供将要下载的文章(章节)链接。我们这里是重写了parse_index方法。
文章解析
因为在下载文章时,其中我们只需要正文内容。recipe也提供了很多方法剔除不相干的内容。这里,我们是用了recipe提供的keep_only_tags变量,即保留指定的标签。
下面是我具体的代码,很简单。
#!/usr/bin/env python2# vim:fileencoding=utf-8from __future__ import unicode_literals, division, absolute_import, print_functionfrom calibre.web.feeds.news import BasicNewsRecipefrom urlparse import urljoinclass AdvancedUserRecipe1498546263(BasicNewsRecipe): title = u'puashu.com' __author__ = u'Mr.cheng' no_stylesheets = True #CHANGE HERE INDEX = 'http://www.puashu.com/0/25/' language = 'zh-CN' max_articles_per_feed = 100 #auto_cleanup = True keep_only_tags = [{'id': ['chapterContent']}] def parse_index(self): soup = self.index_to_soup(self.INDEX) articles=[] div = soup.find('div', { 'class': 'chapter-bd' }) for atag in div.findAll('a'): articles.append({'title':atag.string,'url':urljoin(self.INDEX,atag.get('href'))}) return [(soup.title.string,articles)] def get_cover_url(self): #CHANGE HERE return u'http://www.puashu.com/files/article/image/0/25/25s.jpg'
推荐阅读
[1]. calibre recipes中文API文档
阅读全文
0 0
- calibre recipe制作-puashu.com的recipe示例
- calibre的recipe接口(API)之——参数设置
- calibre抓取“爱上中文”网小说的recipe
- calibre recipe抓取中没有注意的空格
- http://www.haodou.com/recipe/483961
- 配置recipe
- 好吃的豆角回锅肉啊http://www.haodou.com/recipe/510485
- 解释器的原则(Recipe)
- ObjectMapper的使用举例 Recipe.swift
- Advanced Rails Recipe ( 一 )
- Oracle DB Tuning recipe
- RMAN Recipe Note 1
- codechef Recipe Reconstruction 题解
- python django recipe app
- Prototype pattern (Python recipe)
- program design recipe
- 写Recipe(四)
- Recipe 2.16. Walking Directory Trees
- C# datagridview使用
- JavaScript
- sql注入基础总结
- 30 字符串处理命令
- 【EJB】(一)EJB初了解
- calibre recipe制作-puashu.com的recipe示例
- 华扬老师来组里交流教授如何read/write paper
- 文章标题 boost指针的引用计数,以及引发的资源共享和boost指针的交叉问题
- MeritMS成果带附件和校审记录
- 初始Mybatis环境配置
- Laravel 的实用功能之一 数据库填充 使用数据工场
- Material Design-Android 设计简介
- Spark的运行模式
- 欢迎使用CSDN-markdown编辑器