Update Spectator Magazine

This commit is contained in:
Kovid Goyal 2015-10-08 11:32:57 +05:30
parent 6f0403bffe
commit bc0c3d90a6

View File

@ -14,10 +14,14 @@ class Spectator(BasicNewsRecipe):
no_stylesheets = True no_stylesheets = True
keep_only_tags = dict(name='div', attrs={'class':['article-head', 'article-image', 'article-body']}) keep_only_tags = dict(name='div', attrs={'class':['article-header__text', 'featured-image', 'article-content']})
remove_tags = [ remove_tags = [
dict(name='div', attrs={'id':['disqus_thread']}), dict(name='div', attrs={'id':['disqus_thread']}),
dict(attrs={'class':['middle-promo']}), dict(attrs={'class':['middle-promo', 'sharing', 'mejs-player-holder']}),
dict(name='a', onclick=lambda x: x and '__gaTracker' in x and 'outbound-article' in x),
]
remove_tags_after = [
dict(name='hr', attrs={'class':'sticky-clear'}),
] ]
def parse_spec_section(self, div): def parse_spec_section(self, div):
@ -26,13 +30,13 @@ class Spectator(BasicNewsRecipe):
self.log('Section:', sectitle) self.log('Section:', sectitle)
articles = [] articles = []
for div in div.findAll('div', id=lambda x: x and x.startswith('post-')): for div in div.findAll('div', id=lambda x: x and x.startswith('post-')):
h2 = div.find('h2', attrs={'class':class_sel('post-title')}) h2 = div.find('h2', attrs={'class':class_sel('term-item__title')})
title = self.tag_to_string(h2) title = self.tag_to_string(h2)
a = h2.find('a') a = h2.find('a')
url = a['href'] url = a['href']
desc = '' desc = ''
self.log('\tArticle:', title) self.log('\tArticle:', title)
p = div.find('p') p = div.find(attrs={'class':class_sel('term-item__excerpt')})
if p is not None: if p is not None:
desc = self.tag_to_string(p) desc = self.tag_to_string(p)
articles.append({'title':title, 'url':url, 'description':desc}) articles.append({'title':title, 'url':url, 'description':desc})
@ -40,13 +44,15 @@ class Spectator(BasicNewsRecipe):
def parse_index(self): def parse_index(self):
soup = self.index_to_soup('http://www.spectator.co.uk/magazine/') soup = self.index_to_soup('http://www.spectator.co.uk/magazine/')
a = soup.find('a', attrs={'class':'magazine-issue-wrap'}) a = soup.find('a', attrs={'class':'issue-details__cover-link'})
self.timefmt = a['title'] self.timefmt = a['title']
self.cover_url = a['href'] self.cover_url = a['href']
if self.cover_url.startswith('//'):
self.cover_url = 'http:' + self.cover_url
feeds = [] feeds = []
div = soup.find(id='magazine-full') div = soup.find(attrs={'class':class_sel('content-area')})
for x in div.findAll(attrs={'class':class_sel('magazine-section-holder')}): for x in div.findAll(attrs={'class':class_sel('magazine-section-holder')}):
title, articles = self.parse_spec_section(x) title, articles = self.parse_spec_section(x)
if articles: if articles: