Skip to content

Instantly share code, notes, and snippets.

Last active August 9, 2019 16:50
Show Gist options
  • Save zellux/5844688 to your computer and use it in GitHub Desktop.
Save zellux/5844688 to your computer and use it in GitHub Desktop.
知乎日报 Kindle 版生成工具,可用于 Calibre
#!/usr/bin/env python
__copyright__ = 'Yuanxuan Wang <zellux at gmail dot com>'
from import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
from collections import OrderedDict
from contextlib import nested, closing
import json
import re
class Zhihu(BasicNewsRecipe):
INDEX = ''
title = u'知乎日报'
language = 'zh'
__author__ = "Yuanxuan Wang"
description = (u'知乎日报')
no_stylesheets = True
needs_subscription = False
extra_css = '''
.headline { font-size: x-large; }
.content { word-wrap: break-word; line-height: 1.6em; }
def parse_index(self):
opener = getattr(self.browser, 'open_novisit',
with closing(opener(self.INDEX)) as f:
results =
if not results:
raise RuntimeError('Could not fetch index!')
top_stories = []
news = []
json_obj = json.loads(results)
for item in json_obj['news']:
for item in json_obj['top_stories']:
return [(u'News', news), (u'Top Stories', top_stories)]
def parse_article(self, item):
return {
'title': item['title'],
'date': '',
'description': '',
'url': item['items'][0]['url']
Copy link


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment