mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Newsweek
This commit is contained in:
parent
7588e4cacd
commit
396af5fe81
@ -40,7 +40,7 @@ class Newsweek(BasicNewsRecipe):
|
|||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
root = self.index_to_soup(
|
root = self.index_to_soup(
|
||||||
'http://www.newsweek.com/archive', as_tree=True)
|
'https://www.newsweek.com/archive', as_tree=True)
|
||||||
li = root.xpath(
|
li = root.xpath(
|
||||||
'//ul[contains(@class, "magazine-archive-items")]/li')[0]
|
'//ul[contains(@class, "magazine-archive-items")]/li')[0]
|
||||||
a = li.xpath('descendant::a[@href]')[0]
|
a = li.xpath('descendant::a[@href]')[0]
|
||||||
@ -49,9 +49,13 @@ 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[@id="block-nw-magazine-magazine-features"]')[0]
|
|
||||||
features = []
|
features = []
|
||||||
href_xpath = 'descendant::*[local-name()="h1" or local-name()="h2" or local-name()="h3" or local-name()="h4"]/a[@href]'
|
href_xpath = 'descendant::*[local-name()="h1" or local-name()="h2" or local-name()="h3" or local-name()="h4"]/a[@href]'
|
||||||
|
try:
|
||||||
|
div = root.xpath('//div[@id="block-nw-magazine-magazine-features"]')[0]
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
for a in div.xpath(href_xpath):
|
for a in div.xpath(href_xpath):
|
||||||
title = self.tag_to_string(a)
|
title = self.tag_to_string(a)
|
||||||
article = a.xpath('ancestor::article')[0]
|
article = a.xpath('ancestor::article')[0]
|
||||||
@ -59,8 +63,8 @@ class Newsweek(BasicNewsRecipe):
|
|||||||
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])
|
||||||
self.log(title, url)
|
|
||||||
features.append({'title': title, 'url': href_to_url(a), 'description': desc})
|
features.append({'title': title, 'url': href_to_url(a), 'description': desc})
|
||||||
|
self.log(title, href_to_url(a))
|
||||||
|
|
||||||
index = []
|
index = []
|
||||||
if features:
|
if features:
|
||||||
@ -83,7 +87,7 @@ class Newsweek(BasicNewsRecipe):
|
|||||||
sec = 'Articles'
|
sec = 'Articles'
|
||||||
sections[sec].append(
|
sections[sec].append(
|
||||||
{'title': title, 'url': href_to_url(a), 'description': desc})
|
{'title': title, 'url': href_to_url(a), 'description': desc})
|
||||||
self.log(title, url)
|
self.log(title, href_to_url(a))
|
||||||
if desc:
|
if desc:
|
||||||
self.log('\t' + desc)
|
self.log('\t' + desc)
|
||||||
self.log('')
|
self.log('')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user