mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update General Knowledge Today
Fixes #1817256 [Unable to fetch "General Knowledge today"](https://bugs.launchpad.net/calibre/+bug/1817256)
This commit is contained in:
parent
482b24e888
commit
306959fd4a
@ -1,7 +1,7 @@
|
|||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
|
||||||
|
|
||||||
class Politics(BasicNewsRecipe):
|
class GKT(BasicNewsRecipe):
|
||||||
title = u'General Knowledge Today'
|
title = u'General Knowledge Today'
|
||||||
language = 'en_IN'
|
language = 'en_IN'
|
||||||
__author__ = 'Kovid Goyal'
|
__author__ = 'Kovid Goyal'
|
||||||
@ -12,8 +12,13 @@ class Politics(BasicNewsRecipe):
|
|||||||
no_javascript = True
|
no_javascript = True
|
||||||
auto_cleanup = True
|
auto_cleanup = True
|
||||||
|
|
||||||
def parse_gkt_section(self, url):
|
def parse_gkt_section(self, url, ignore_error=False):
|
||||||
root = self.index_to_soup(url, as_tree=True)
|
try:
|
||||||
|
root = self.index_to_soup(url, as_tree=True)
|
||||||
|
except Exception:
|
||||||
|
if ignore_error:
|
||||||
|
return
|
||||||
|
raise
|
||||||
for a in root.xpath('//div[@class="post-content"]/h1/a[@href]'):
|
for a in root.xpath('//div[@class="post-content"]/h1/a[@href]'):
|
||||||
title = self.tag_to_string(a).strip()
|
title = self.tag_to_string(a).strip()
|
||||||
url = a.get('href')
|
url = a.get('href')
|
||||||
@ -28,12 +33,12 @@ class Politics(BasicNewsRecipe):
|
|||||||
h3 = root.xpath('//h3[@class="widget-title"]')[1]
|
h3 = root.xpath('//h3[@class="widget-title"]')[1]
|
||||||
for a in h3.getparent().xpath('descendant::li/a[@href]'):
|
for a in h3.getparent().xpath('descendant::li/a[@href]'):
|
||||||
category = self.tag_to_string(a).strip()
|
category = self.tag_to_string(a).strip()
|
||||||
if 'PDF' in category:
|
if 'PDF' in category or not category:
|
||||||
continue
|
continue
|
||||||
url = a.get('href')
|
url = a.get('href')
|
||||||
self.log('Found section:', category)
|
self.log('Found section:', category)
|
||||||
articles = list(self.parse_gkt_section(url)) + \
|
articles = list(self.parse_gkt_section(url)) + \
|
||||||
list(self.parse_gkt_section(url + '/page/2'))
|
list(self.parse_gkt_section(url + '/page/2', ignore_error=True))
|
||||||
if articles:
|
if articles:
|
||||||
ans.append((category, articles))
|
ans.append((category, articles))
|
||||||
return ans
|
return ans
|
||||||
|
Loading…
x
Reference in New Issue
Block a user