• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
梧桐爱凤
博客园    首页    新随笔    联系   管理    订阅  订阅

Kindle:自动追更之Calibre2脚本

 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 rdzs(BasicNewsRecipe):
 7     title          = '儒道至圣'
 8     description = '这是一个读书人掌握天地之力的世界。  才气在身,诗可杀敌,词能灭军,文章安天下。  秀才提笔,纸上谈兵;举人杀敌,出口成章;进士一怒,唇枪舌剑。  圣人驾临,口诛笔伐,可诛人,可判天子无道,以一敌国。  此时,圣院把持文位,国君掌官位,十国相争,蛮族虎视,群妖作乱。  此时,无唐诗大兴,无宋词鼎盛,无创新文章,百年无新圣。  一个默默无闻的寒门子弟,被人砸破头后,挟传世诗词,书惊圣文章,踏上至圣之路。'
 9     max_articles_per_feed = 20000
10     fileName = 'xx/rdzs.txt'
11     cover_url  = 'http://www.50zw.la/files/article/image/2/2806/2806s.jpg' 
12     no_stylesheets = True
13     keep_only_tags = [dict(name='div', attrs={'class':'h1title'}),dict(name='div', attrs={'id':'htmlContent'})]
14     url_prefix = 'http://www.xxbiquge.com'   
15     no_stylesheets = True
16     keep_only_tags = [dict(name='div', attrs={'class':'bookname'}),dict(name='div', attrs={'id':'content'})]
17     file_object = open(fileName,'r')
18     lastHref = file_object.read()
19     file_object.close()
20     hasLoad = bool(lastHref)
21 
22     def get_title(self, link):
23         return link.contents[0].strip()
24     
25     def parse_index(self):
26         soup = self.index_to_soup(self.url_prefix+"/5_5690")
27  
28         div = soup.find('div', { 'id': 'list' })
29         lastHref =self.lastHref
30         articles = []
31         for link in div.findAll('a'):
32             til = self.get_title(link)         
33             href = link['href']
34             self.lastHref = href
35             if href == lastHref:
36                 self.hasLoad = False
37             if self.hasLoad:
38                 continue
39             else:
40                 url = self.url_prefix + href
41                 a = { 'title': til, 'url': url }
42                 articles.append(a)
43  
44         tutorial = [(self.title, articles)]
45         file_write = open(self.fileName,'w')
46         file_write.write(self.lastHref)
47         file_write.flush()
48         file_write.close()
49         return tutorial

  说明:

fileName :是为了简单的记录一下最后一次更新的网址,避免每次都全部更新

上述代码的详细讲解可以看:http://abirdcfly.github.io/2016/03/07/calibre2mobi/
每多学一点知识,就少写一行代码
posted @ 2017-05-27 13:43  梧桐爱凤  阅读(899)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3