用calibre脚本抓取ipdf的epub 3.0.1规范
Epub规范已经更新到了3.0.1版本,一直以来都有是在
ipdf网站在线浏览,该网站没有提供下载,有时阅读和查找时总觉不是很方便。
EPUB 3.0.1 Changes from EPUB 3.0七个文档,每个文档均为一个页面,页面内每个标题用锚点来处理。一直希望能有一个pdf版或者epub的规范下载,网上找了一下没有找到(3.0版的只有一个内容文档的中文版,大家可以在网上查到,其它独立文档没有见到下载)。于是就想自己下一个,碰巧看到calibre抓取网页一文,于是搞了个recipe:
title = 'Epub 3.0.1 Specs'
description = 'Epub 3.0.1 Specs'
url_prefix = 'http://www.idpf.org/epub/301'
no_stylesheets = True
def get_title(self, link):
return link.contents[0].strip()
def parse_index(self):
soup = self.index_to_soup(self.url_prefix )
ul = soup.find('ul', { 'class': 'menu' })
articles = []
for link in ul.findAll('a'):
til = self.get_title(link)
url = link['href']
a = { 'title': til, 'url': url }
articles.append(a)
ans = [('Epub 3.0.1 Specs', articles)]
return ans
该规范包含
EPUB 3 Overview
from calibre.web.feeds.recipes import BasicNewsRecipe
class ipdf(BasicNewsRecipe):
就是一小段python,保存成ipdf.recipe
在命令行下,到calibre文件夹下,执行ebook-convert.exe ipdf.recipe epub301.epub
自动抓取网页,在当前文件夹下生成epub301.epub
或者执行 ebook-convert.exe ipdf.recipe epub301.pdf
生成epub301.pdf
文档都有是只有一级目录,如果想更强一点,把二级目录也制作出来,可以用sigil或者acrobat pro编辑处理一下。calibre还是不错的,但抓取生成的电子书限制也不少,而且写recipe后调试比较痛苦,不能用python的集成开发环境,只能用内嵌脚本和输出日志来调试。不过也很方便,可以生成基本上各种常用格式的电子书。
因为本博客限制,不再放上生成的电子书和recipe文件。如有需要,可以联系我。