Update Newsweek

This commit is contained in:
Kovid Goyal 2018-08-04 13:45:36 +05:30
parent 7588e4cacd
commit 396af5fe81
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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,18 +49,22 @@ 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]'
for a in div.xpath(href_xpath): try:
title = self.tag_to_string(a) div = root.xpath('//div[@id="block-nw-magazine-magazine-features"]')[0]
article = a.xpath('ancestor::article')[0] except IndexError:
desc = '' pass
s = article.xpath('descendant::div[@class="summary"]') else:
if s: for a in div.xpath(href_xpath):
desc = self.tag_to_string(s[0]) title = self.tag_to_string(a)
self.log(title, url) article = a.xpath('ancestor::article')[0]
features.append({'title': title, 'url': href_to_url(a), 'description': desc}) desc = ''
s = article.xpath('descendant::div[@class="summary"]')
if s:
desc = self.tag_to_string(s[0])
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('')