diff --git a/recipes/wsj.recipe b/recipes/wsj.recipe index d3938f6b26..c1c63c4020 100644 --- a/recipes/wsj.recipe +++ b/recipes/wsj.recipe @@ -164,26 +164,32 @@ class WSJ(BasicNewsRecipe): return soup def _download_cover(self): - d = self.recipe_specific_options.get('date') - if not (d and isinstance(d, str)): - import os - from contextlib import closing + import os + from contextlib import closing - from calibre.utils.img import save_cover_data_to + from calibre.utils.img import save_cover_data_to - br = browser() - raw = br.open('https://www.frontpages.com/the-wall-street-journal/') + br = browser() + dt = self.recipe_specific_options.get('date') + if (dt and isinstance(dt, str)): + d, m, y = dt.split('-') + cu = f'https://www.wsj.com/public/resources/documents/WSJNewsPaper-{int(m)}-{int(d)}-{y}.jpg' + else: + raw = br.open('https://wsjtodaysedition.cmail19.com/t/d-e-suujjg-thithlkhlr-r/') soup = BeautifulSoup(raw.read()) - cu = ( - 'https://www.frontpages.com' - + soup.find('img', attrs={'id': 'giornale-img'})['src'] - ) - self.report_progress(1, _('Downloading cover from %s') % cu) - with closing(br.open(cu, timeout=self.timeout)) as r: - cdata = r.read() - cpath = os.path.join(self.output_dir, 'cover.jpg') - save_cover_data_to(cdata, cpath) - self.cover_path = cpath + cu = soup.find( + 'img', + attrs={ + 'class': 'responsive-img', + 'src': lambda x: x and 'WSJNewsPaper' in x + } + )['src'] + self.report_progress(1, _('Downloading cover from %s') % cu) + with closing(br.open(cu, timeout=self.timeout)) as r: + cdata = r.read() + cpath = os.path.join(self.output_dir, 'cover.jpg') + save_cover_data_to(cdata, cpath) + self.cover_path = cpath def get_browser(self, *args, **kw): br = BasicNewsRecipe.get_browser(self, *args, **kw)