This commit is contained in:
Kovid Goyal 2016-11-15 20:33:57 +05:30
parent c4b9994629
commit 553912d235

View File

@ -61,31 +61,27 @@ class ForeignAffairsRecipe(BasicNewsRecipe):
self.title = "Foreign Affairs ({})".format(date) self.title = "Foreign Affairs ({})".format(date)
self.timefmt = u' [%s]' % date self.timefmt = u' [%s]' % date
sec_start = soup.findAll( for section in soup.findAll(attrs={'class':lambda x: x and 'magazine-list' in x.split()}):
'section', attrs={'class': re.compile(r'\bmagazine-list\b')})
for sec in sec_start:
articles = [] articles = []
section = self.tag_to_string(sec.find('h1')) section_title = self.tag_to_string(section.find('h1'))
for article_block in sec.findAll('article'): for h2 in section.findAll('h2'):
if article_block.find('a') is not None: a = h2.parent
title = self.tag_to_string(article_block.div.a.h2) if a.get('href'):
url = article_block.div.a['href'] title = self.tag_to_string(h2)
atr = article_block.findNext( url = a['href']
'p', attrs={'class': 'author'}) atr = a.findNextSibling(attrs={'class':'author'})
if atr is not None: author = self.tag_to_string(atr) if atr else ''
author = self.tag_to_string(atr) desc = a.findNextSibling(attrs={'class': 'deck'})
else:
author = ''
desc = article_block.findNext(
'div', attrs={'class': 'deck'})
if desc is not None: if desc is not None:
description = self.tag_to_string(desc) description = self.tag_to_string(desc)
else: else:
description = '' description = ''
articles.append({'title': title, 'date': None, 'url': url, articles.append({'title': title, 'url': url,
'description': description, 'author': author}) 'description': description, 'author': author})
self.log(title)
self.log('\t' + url)
if articles: if articles:
answer.append((section, articles)) answer.append((section_title, articles))
return answer return answer
def clean_fa_html(self, root): def clean_fa_html(self, root):