From 5d3ec0672ff5ad4a9e59374a84324d30a4675168 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 30 Jan 2013 10:59:00 +0530 Subject: [PATCH] Fix Harvard Business Review --- recipes/hbr.recipe | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/recipes/hbr.recipe b/recipes/hbr.recipe index 54c0f258d8..742d1605fa 100644 --- a/recipes/hbr.recipe +++ b/recipes/hbr.recipe @@ -11,11 +11,11 @@ class HBR(BasicNewsRecipe): timefmt = ' [%B %Y]' language = 'en' no_stylesheets = True - recipe_disabled = ('hbr.org has started requiring the use of javascript' - ' to log into their website. This is unsupported in calibre, so' - ' this recipe has been disabled. If you would like to see ' - ' HBR supported in calibre, contact hbr.org and ask them' - ' to provide a javascript free login method.') + # recipe_disabled = ('hbr.org has started requiring the use of javascript' + # ' to log into their website. This is unsupported in calibre, so' + # ' this recipe has been disabled. If you would like to see ' + # ' HBR supported in calibre, contact hbr.org and ask them' + # ' to provide a javascript free login method.') LOGIN_URL = 'https://hbr.org/login?request_url=/' LOGOUT_URL = 'https://hbr.org/logout?request_url=/' @@ -50,21 +50,25 @@ class HBR(BasicNewsRecipe): f = br.select_form('#signin-form') f['signin-form:username'] = 'test-account' f['signin-form:password'] = 'testaccount' - br.submit(ajax_replies=3) + f.submit_control().qwe.evaluateJavaScript('this.click()') + br.run_for_a_time(30) def map_url(self, url): if url.endswith('/ar/1'): return url[:-1]+'pr' def hbr_get_toc(self): - #return self.index_to_soup(open('/t/hbr.html').read()) + # return self.index_to_soup(open('/t/toc.html').read()) today = date.today() future = today + timedelta(days=30) for x in [x.strftime('%y%m') for x in (future, today)]: url = self.INDEX + x soup = self.index_to_soup(url) - if not soup.find(text='Issue Not Found'): + if (not soup.find(text='Issue Not Found') and not soup.find( + text="We're Sorry. There was an error processing your request") + and 'Exception: java.io.FileNotFoundException' not in + unicode(soup)): return soup raise Exception('Could not find current issue') @@ -72,8 +76,9 @@ class HBR(BasicNewsRecipe): feeds = [] current_section = None articles = [] - for x in soup.find(id='archiveToc').findAll(['h3', 'h4']): - if x.name == 'h3': + for x in soup.find(id='issueFeaturesContent').findAll(['li', 'h4']): + if x.name == 'h4': + if x.get('class', None) == 'basic':continue if current_section is not None and articles: feeds.append((current_section, articles)) current_section = self.tag_to_string(x).capitalize() @@ -89,7 +94,7 @@ class HBR(BasicNewsRecipe): if url.startswith('/'): url = 'http://hbr.org' + url url = self.map_url(url) - p = x.parent.find('p') + p = x.find('p', attrs={'class':'author'}) desc = '' if p is not None: desc = self.tag_to_string(p) @@ -101,10 +106,9 @@ class HBR(BasicNewsRecipe): 'date':''}) return feeds - def parse_index(self): soup = self.hbr_get_toc() - #open('/t/hbr.html', 'wb').write(unicode(soup).encode('utf-8')) + # open('/t/hbr.html', 'wb').write(unicode(soup).encode('utf-8')) feeds = self.hbr_parse_toc(soup) return feeds