The current recipe by Mr Darko Miletic for the Singapore Straits Times is no longer working. I made some changes here to make it work again.
I don't why most of the images won't load. Is it because they are enclosed within the <IMAGES> tags or they use "IMG SRCSET" instead of "IMG SRC"?
Spoiler:
Code:
__license__ = 'GPL v3'
__copyright__ = '2009, Darko Miletic <darko.miletic at gmail.com>'
'''
www.straitstimes.com
'''
import re
from calibre.web.feeds.recipes import BasicNewsRecipe
class StraitsTimes(BasicNewsRecipe):
title = 'The Straits Times'
__author__ = 'Darko Miletic'
description = 'Singapore newspaper'
oldest_article = 2
max_articles_per_feed = 100
no_stylesheets = True
use_embedded_content = False
encoding = 'utf-8'
publisher = 'Singapore Press Holdings Ltd.'
category = 'news, politics, singapore, asia'
language = 'en_SG'
conversion_options = {
'comments' : description
,'tags' : category
,'language' : language
,'publisher' : publisher
}
preprocess_regexps = [
(re.compile(
r'<meta name="description" content="[^"]+"\s*/?>',
re.IGNORECASE|re.DOTALL),
lambda m:''),
(re.compile(r'<!--.+?-->', re.IGNORECASE|re.DOTALL),
lambda m: ''),
]
remove_tags = [
dict(name=['object','link','map', 'style']),
dict(attrs={'class':'dropdown-menu'}),
]
keep_only_tags = [
dict(name='h1', attrs={'class':'headline node-title'}),
dict(name='div', attrs={'class':'media-group'}),
dict(name='div', attrs={'itemprop':'articleBody'})
]
remove_tags_after=dict(name='div',attrs={'class':'story-keywords hidden-print '})
feeds = [
(u'Singapore' , u'http://www.straitstimes.com/news/singapore/rss.xml' )
,(u'Asia' , u'http://www.straitstimes.com/news/asia/rss.xml' )
,(u'Business' , u'http://www.straitstimes.com/news/business/rss.xml' )
,(u'Sport' , u'http://www.straitstimes.com/news/sport/rss.xml' )
,(u'World' , u'http://www.straitstimes.com/news/world/rss.xml' )
,(u'Lifestyle' , u'http://www.straitstimes.com/news/lifestyle/rss.xml' )
]
def preprocess_html(self, soup):
for a in soup.findAll('a', attrs={'class':'thumb'}):
img = a.find('img')
if img is not None:
img['src'] = a['href']
return soup