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
b702e94090
commit
408990ffd8
@ -49,17 +49,16 @@ class Newsweek(BasicNewsRecipe):
|
|||||||
a = li.xpath('descendant::a[@href]')[0]
|
a = li.xpath('descendant::a[@href]')[0]
|
||||||
url = href_to_url(a, add_piano=True)
|
url = href_to_url(a, add_piano=True)
|
||||||
self.timefmt = self.tag_to_string(a)
|
self.timefmt = self.tag_to_string(a)
|
||||||
img = li.xpath('descendant::a[@href]//img[@src]')[0]
|
img = li.xpath('descendant::a[@href]//img[@data-src]')[0]
|
||||||
self.cover_url = img.get('src')
|
self.cover_url = img.get('data-src').partition('?')[0]
|
||||||
root = self.index_to_soup(url, as_tree=True)
|
root = self.index_to_soup(url, as_tree=True)
|
||||||
features = []
|
features = []
|
||||||
href_xpath = 'descendant::*[local-name()="h1" or local-name()="h2" or local-name()="h3" or local-name()="h4"]/a[@href]'
|
|
||||||
try:
|
try:
|
||||||
div = root.xpath('//div[@id="block-nw-magazine-magazine-features"]')[0]
|
div = root.xpath('//div[@class="magazine-features"]')[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
for a in div.xpath(href_xpath):
|
for a in div.xpath('descendant::div[@class="h1"]//a[@href]'):
|
||||||
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 = ''
|
||||||
@ -73,34 +72,35 @@ class Newsweek(BasicNewsRecipe):
|
|||||||
if features:
|
if features:
|
||||||
index.append(('Features', features))
|
index.append(('Features', features))
|
||||||
sections = defaultdict(list)
|
sections = defaultdict(list)
|
||||||
for block in ('magazine-magazine-issue-story-list', 'editors-pick'):
|
for widget in ('editor-pick',):
|
||||||
div = root.xpath(
|
self.parse_widget(widget, sections)
|
||||||
'//div[@id="block-nw-{}"]'.format(block))
|
|
||||||
if not div:
|
|
||||||
continue
|
|
||||||
div = div[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, href_to_url(a))
|
|
||||||
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
|
||||||
|
|
||||||
|
def parse_widget(self, widget, sections):
|
||||||
|
root = self.index_to_soup('https://d.newsweek.com/widget/' + widget, as_tree=True)
|
||||||
|
div = root.xpath('//div')[0]
|
||||||
|
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):
|
||||||
|
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, href_to_url(a))
|
||||||
|
if desc:
|
||||||
|
self.log('\t' + desc)
|
||||||
|
self.log('')
|
||||||
|
|
||||||
def print_version(self, url):
|
def print_version(self, url):
|
||||||
return url + '?piano_d=1'
|
return url + '?piano_d=1'
|
||||||
|
|
||||||
@ -114,4 +114,6 @@ class Newsweek(BasicNewsRecipe):
|
|||||||
s['style'] = 'display: block'
|
s['style'] = 'display: block'
|
||||||
s.name = 'img'
|
s.name = 'img'
|
||||||
s['src'] = url
|
s['src'] = url
|
||||||
|
for img in soup.findAll('img', attrs={'data-src': True}):
|
||||||
|
img['src'] = img['data-src']
|
||||||
return soup
|
return soup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user