Update NRC

This commit is contained in:
Kovid Goyal 2015-10-22 10:22:32 +05:30
parent eb18b57463
commit 8dd12103d1

View File

@ -5,6 +5,7 @@ nrc.nl
''' '''
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import Tag
class Pagina12(BasicNewsRecipe): class Pagina12(BasicNewsRecipe):
title = 'NRC' title = 'NRC'
@ -21,56 +22,25 @@ class Pagina12(BasicNewsRecipe):
country = 'NL' country = 'NL'
remove_empty_feeds = True remove_empty_feeds = True
masthead_url = 'http://www.nrc.nl/nrc.nl/images/logo_nrc.png' masthead_url = 'http://www.nrc.nl/nrc.nl/images/logo_nrc.png'
extra_css = """
body{font-family: Georgia,serif }
img{margin-bottom: 0.4em; display: block}
.bijschrift,.sectie{font-size: x-small}
.sectie{color: gray}
"""
conversion_options = { keep_only_tags = [
'comment' : description dict(name=['h1', 'figure']),
, 'tags' : category dict(attrs={'class':['intro', 'byline']}),
, 'publisher' : publisher dict(attrs={'class':lambda x: x and 'article__content' in x}),
, 'language' : language
}
keep_only_tags = [dict(attrs={'class':'uitstekendekeus'})]
remove_tags = [
dict(name=['meta','base','link','object','embed'])
,dict(attrs={'class':['reclamespace','tags-and-sharing','sharing-is-caring']})
] ]
remove_attributes=['lang'] remove_attributes = ['style']
feeds = [ feeds = ['http://www.nrc.nl/rss/']
(u'Voor nieuws', u'http://www.nrc.nl/nieuws/categorie/nieuws/rss.php' )
,(u'Binnenland' , u'http://www.nrc.nl/nieuws/categorie/binnenland/rss.php' )
,(u'Buitenland' , u'http://www.nrc.nl/nieuws/categorie/buitenland/rss.php' )
,(u'Economie' , u'http://www.nrc.nl/nieuws/categorie/economie/rss.php' )
,(u'Cultuur' , u'http://www.nrc.nl/nieuws/categorie/cultuur/rss.php' )
,(u'Sport' , u'http://www.nrc.nl/nieuws/categorie/sport/rss.php' )
,(u'Wetenschap ', u'http://www.nrc.nl/nieuws/categorie/wetenschap-nieuws/rss.php')
]
def preprocess_html(self, soup): def preprocess_html(self, soup):
for item in soup.findAll(style=True): src = None
del item['style'] for meta in soup.findAll('meta', itemprop='image', content=True):
for item in soup.findAll('a'): src = meta['content']
limg = item.find('img') break
if item.string is not None: if src is not None:
str = item.string div = soup.find('div', attrs={'class':lambda x: x and 'featured-img' in x})
item.replaceWith(str) if div is not None:
else: img = Tag(soup, 'img')
if limg: img['src'] = src
item.name = 'div' div.append(img)
atritems =['href','target','rel']
for atit in atritems:
if item.has_key(atit):
del item[atit]
else:
str = self.tag_to_string(item)
item.replaceWith(str)
for item in soup.findAll('img'):
if not item.has_key('alt'):
item['alt'] = 'image'
return soup return soup