mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Update Newsweek
This commit is contained in:
parent
d82d6f823c
commit
472fc44c70
@ -49,31 +49,44 @@ class Newsweek(BasicNewsRecipe):
|
|||||||
img = li.xpath('descendant::a[@href]/img[@src]')[0]
|
img = li.xpath('descendant::a[@href]/img[@src]')[0]
|
||||||
self.cover_url = img.get('src')
|
self.cover_url = img.get('src')
|
||||||
root = self.index_to_soup(url, as_tree=True)
|
root = self.index_to_soup(url, as_tree=True)
|
||||||
div = root.xpath(
|
div = root.xpath('//div[@id="block-nw-magazine-magazine-features"]')[0]
|
||||||
'//div[@id="block-nw-magazine-magazine-cover-story"]')[0]
|
features = []
|
||||||
a = div.xpath('descendant::a[@href]')[0]
|
href_xpath = 'descendant::*[local-name()="h1" or local-name()="h2" or local-name()="h3" or local-name()="h4"]/a[@href]'
|
||||||
index = [('Cover', [{'title': 'Cover story', 'url': href_to_url(a)}])]
|
for a in div.xpath(href_xpath):
|
||||||
sections = defaultdict(list)
|
|
||||||
div = root.xpath(
|
|
||||||
'//div[@id="block-nw-magazine-magazine-issue-story-list"]')[0]
|
|
||||||
for a in div.xpath('descendant::h3/a[@href and contains(@class, "article-link")]'):
|
|
||||||
title = self.tag_to_string(a)
|
title = self.tag_to_string(a)
|
||||||
article = a.xpath('ancestor::article')[0]
|
article = a.xpath('ancestor::article')[0]
|
||||||
desc = ''
|
desc = ''
|
||||||
s = article.xpath('descendant::div[@class="summary"]')
|
s = article.xpath('descendant::div[@class="summary"]')
|
||||||
if s:
|
if s:
|
||||||
desc = self.tag_to_string(s[0])
|
desc = self.tag_to_string(s[0])
|
||||||
sec = article.xpath('descendant::div[@class="category"]')
|
|
||||||
if sec:
|
|
||||||
sec = self.tag_to_string(sec[0])
|
|
||||||
else:
|
|
||||||
sec = 'Articles'
|
|
||||||
sections[sec].append(
|
|
||||||
{'title': title, 'url': href_to_url(a), 'description': desc})
|
|
||||||
self.log(title, url)
|
self.log(title, url)
|
||||||
if desc:
|
features.append({'title': title, 'url': href_to_url(a), 'description': desc})
|
||||||
self.log('\t' + desc)
|
|
||||||
self.log('')
|
index = []
|
||||||
|
if features:
|
||||||
|
index.append(('Features', features))
|
||||||
|
sections = defaultdict(list)
|
||||||
|
for block in ('magazine-magazine-issue-story-list', 'editors-pick'):
|
||||||
|
div = root.xpath(
|
||||||
|
'//div[@id="block-nw-{}"]'.format(block))[0]
|
||||||
|
for a in div.xpath(href_xpath):
|
||||||
|
title = self.tag_to_string(a)
|
||||||
|
article = a.xpath('ancestor::article')[0]
|
||||||
|
desc = ''
|
||||||
|
s = article.xpath('descendant::div[@class="summary"]')
|
||||||
|
if s:
|
||||||
|
desc = self.tag_to_string(s[0])
|
||||||
|
sec = article.xpath('descendant::div[@class="category"]')
|
||||||
|
if sec:
|
||||||
|
sec = self.tag_to_string(sec[0])
|
||||||
|
else:
|
||||||
|
sec = 'Articles'
|
||||||
|
sections[sec].append(
|
||||||
|
{'title': title, 'url': href_to_url(a), 'description': desc})
|
||||||
|
self.log(title, url)
|
||||||
|
if desc:
|
||||||
|
self.log('\t' + desc)
|
||||||
|
self.log('')
|
||||||
for k in sorted(sections):
|
for k in sorted(sections):
|
||||||
index.append((k, sections[k]))
|
index.append((k, sections[k]))
|
||||||
return index
|
return index
|
||||||
|
Loading…
x
Reference in New Issue
Block a user