From 840ca8092b5a1f559158854b2886047b85d0bb15 Mon Sep 17 00:00:00 2001 From: Gary Arnold Date: Mon, 5 Mar 2018 14:19:30 -0800 Subject: [PATCH] ga - More resilient with different title/author formatting --- recipes/granta.recipe | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/recipes/granta.recipe b/recipes/granta.recipe index d85b47ac61..af64509fb7 100644 --- a/recipes/granta.recipe +++ b/recipes/granta.recipe @@ -257,9 +257,20 @@ class Granta(BasicNewsRecipe): # Either user is logged in or the article is unlocked h1 = toc.find('h1') h2 = toc.find('h2') - title = h1.find('a').contents[0].strip() - author = h2.find('a').contents[0].strip() - title = title + u' (%s)' % author + if h1.find('a') is not None and h1.find('a').contents is not None: + title = h1.find('a').contents[0].strip() + elif h1.contents[0] is not None: + title = h1.contents[0] + else: + title = '' + if h2.find('a') is not None and h2.find('a').contents is not None: + author = h2.find('a').contents[0].strip() + title = title + u' (%s)' % author + elif h2.contents[0] is not None: + author = h2.contents[0] + title = title + u' (%s)' % author + else: + author = '' url = absurl(h1.find('a', href=True)['href']) self.log.info('Found article:', title) self.log.info('\t', url)