From 97f9373a999fe9baf9d48da3e88bc7afa41ca7a5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 16 Nov 2018 12:24:41 +0530 Subject: [PATCH] Economist: handle printedition page redirecting to previous issue instead of current one --- recipes/economist.recipe | 6 ++++++ recipes/economist_free.recipe | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/recipes/economist.recipe b/recipes/economist.recipe index 57718ce413..0d347f5fcf 100644 --- a/recipes/economist.recipe +++ b/recipes/economist.recipe @@ -167,6 +167,12 @@ class Economist(BasicNewsRecipe): # with open('/t/raw.html', 'wb') as f: # f.write(raw) soup = self.index_to_soup(raw) + nav = soup.find(attrs={'class':'navigation__wrapper'}) + if nav is not None: + a = nav.find('a', href=lambda x: x and '/printedition/' in x) + if a is not None: + self.log('Following nav link to current edition', a['href']) + soup = self.index_to_soup(process_url(a['href'])) ans = self.economist_parse_index(soup) if not ans: raise NoArticles( diff --git a/recipes/economist_free.recipe b/recipes/economist_free.recipe index 57718ce413..0d347f5fcf 100644 --- a/recipes/economist_free.recipe +++ b/recipes/economist_free.recipe @@ -167,6 +167,12 @@ class Economist(BasicNewsRecipe): # with open('/t/raw.html', 'wb') as f: # f.write(raw) soup = self.index_to_soup(raw) + nav = soup.find(attrs={'class':'navigation__wrapper'}) + if nav is not None: + a = nav.find('a', href=lambda x: x and '/printedition/' in x) + if a is not None: + self.log('Following nav link to current edition', a['href']) + soup = self.index_to_soup(process_url(a['href'])) ans = self.economist_parse_index(soup) if not ans: raise NoArticles(