mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
get the economist cover url from json
This commit is contained in:
parent
57302df132
commit
84741b17df
@ -264,20 +264,9 @@ class Economist(BasicNewsRecipe):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def economist_parse_index(self, soup):
|
def economist_parse_index(self, soup):
|
||||||
img = None
|
if (tag := soup.select_one("script#__NEXT_DATA__")) is not None:
|
||||||
if edition_date:
|
data = json.loads(tag.string)
|
||||||
archive_url = "https://www.economist.com/weeklyedition/archive?year={}".format(edition_date[:4])
|
self.cover_url = data['props']['pageProps']['content']['image']['main']['url']['canonical']
|
||||||
archive = self.index_to_soup(archive_url)
|
|
||||||
q = edition_date.replace('-', '')
|
|
||||||
q = '/print-covers/{}_'.format(q)
|
|
||||||
img = archive.find('img', srcset=lambda x: x and q in x)
|
|
||||||
else:
|
|
||||||
archive = self.index_to_soup("https://www.economist.com/weeklyedition/archive")
|
|
||||||
div = archive.find(attrs={'class': 'edition-teaser__image'})
|
|
||||||
if div is not None:
|
|
||||||
img = div.find('img', srcset=True)
|
|
||||||
if img:
|
|
||||||
self.cover_url = img['srcset'].split(',')[-1].split()[0]
|
|
||||||
self.log('Got cover:', self.cover_url)
|
self.log('Got cover:', self.cover_url)
|
||||||
feeds = []
|
feeds = []
|
||||||
for section in soup.findAll(**classes('layout-weekly-edition-section')):
|
for section in soup.findAll(**classes('layout-weekly-edition-section')):
|
||||||
|
@ -264,20 +264,9 @@ class Economist(BasicNewsRecipe):
|
|||||||
return ans
|
return ans
|
||||||
|
|
||||||
def economist_parse_index(self, soup):
|
def economist_parse_index(self, soup):
|
||||||
img = None
|
if (tag := soup.select_one("script#__NEXT_DATA__")) is not None:
|
||||||
if edition_date:
|
data = json.loads(tag.string)
|
||||||
archive_url = "https://www.economist.com/weeklyedition/archive?year={}".format(edition_date[:4])
|
self.cover_url = data['props']['pageProps']['content']['image']['main']['url']['canonical']
|
||||||
archive = self.index_to_soup(archive_url)
|
|
||||||
q = edition_date.replace('-', '')
|
|
||||||
q = '/print-covers/{}_'.format(q)
|
|
||||||
img = archive.find('img', srcset=lambda x: x and q in x)
|
|
||||||
else:
|
|
||||||
archive = self.index_to_soup("https://www.economist.com/weeklyedition/archive")
|
|
||||||
div = archive.find(attrs={'class': 'edition-teaser__image'})
|
|
||||||
if div is not None:
|
|
||||||
img = div.find('img', srcset=True)
|
|
||||||
if img:
|
|
||||||
self.cover_url = img['srcset'].split(',')[-1].split()[0]
|
|
||||||
self.log('Got cover:', self.cover_url)
|
self.log('Got cover:', self.cover_url)
|
||||||
feeds = []
|
feeds = []
|
||||||
for section in soup.findAll(**classes('layout-weekly-edition-section')):
|
for section in soup.findAll(**classes('layout-weekly-edition-section')):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user