mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix National Post
This commit is contained in:
parent
df1195e9ff
commit
61aa60ab07
@ -1,5 +1,4 @@
|
|||||||
from calibre.web.feeds.recipes import BasicNewsRecipe
|
from calibre.web.feeds.recipes import BasicNewsRecipe
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
|
||||||
|
|
||||||
class NYTimes(BasicNewsRecipe):
|
class NYTimes(BasicNewsRecipe):
|
||||||
|
|
||||||
@ -11,22 +10,8 @@ class NYTimes(BasicNewsRecipe):
|
|||||||
needs_subscription = False
|
needs_subscription = False
|
||||||
|
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
#remove_tags_before = dict(name='h1', attrs={'class':'heading'})
|
auto_cleanup = True
|
||||||
remove_tags_after = dict(name='div', attrs={'class':'npStoryTools npWidth1-6 npRight npTxtStrong'})
|
auto_cleanup_keep = '//*[@class="npStoryPhoto npTxtPlain"]'
|
||||||
remove_tags = [
|
|
||||||
dict(name='iframe'),
|
|
||||||
dict(name='div', attrs={'class':['story-tools', 'npStoryTools npWidth1-6 npRight npTxtStrong']}),
|
|
||||||
#dict(name='div', attrs={'id':['qrformdiv', 'inSection', 'alpha-inner']}),
|
|
||||||
#dict(name='form', attrs={'onsubmit':''}),
|
|
||||||
dict(name='ul', attrs={'class':'npTxtAlt npGroup npTxtCentre npStoryShare npTxtStrong npTxtDim'}),
|
|
||||||
]
|
|
||||||
|
|
||||||
# def preprocess_html(self, soup):
|
|
||||||
# table = soup.find('table')
|
|
||||||
# if table is not None:
|
|
||||||
# table.extract()
|
|
||||||
# return soup
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#TO GET ARTICLE TOC
|
#TO GET ARTICLE TOC
|
||||||
@ -53,14 +38,14 @@ class NYTimes(BasicNewsRecipe):
|
|||||||
if current_section is not None and x.name == 'h5':
|
if current_section is not None and x.name == 'h5':
|
||||||
# Article found
|
# Article found
|
||||||
title = self.tag_to_string(x)
|
title = self.tag_to_string(x)
|
||||||
a = x.find('a', href=lambda x: x and 'story' in x)
|
a = x.find('a', href=True)
|
||||||
if a is None:
|
if a is None:
|
||||||
continue
|
continue
|
||||||
url = a.get('href', False)
|
url = a.get('href', False)
|
||||||
if not url or not title:
|
if not url or not title:
|
||||||
continue
|
continue
|
||||||
#if url.startswith('story'):
|
#if url.startswith('story'):
|
||||||
url = 'http://www.nationalpost.com/todays-paper/'+url
|
#url = 'http://www.nationalpost.com/todays-paper/'+url
|
||||||
self.log('\t\tFound article:', title)
|
self.log('\t\tFound article:', title)
|
||||||
self.log('\t\t\t', url)
|
self.log('\t\t\t', url)
|
||||||
current_articles.append({'title': title, 'url':url,
|
current_articles.append({'title': title, 'url':url,
|
||||||
@ -70,11 +55,4 @@ class NYTimes(BasicNewsRecipe):
|
|||||||
feeds.append((current_section, current_articles))
|
feeds.append((current_section, current_articles))
|
||||||
|
|
||||||
return feeds
|
return feeds
|
||||||
def preprocess_html(self, soup):
|
|
||||||
story = soup.find(name='div', attrs={'id':'npContentMain'})
|
|
||||||
##td = heading.findParent(name='td')
|
|
||||||
##td.extract()
|
|
||||||
soup = BeautifulSoup('<html><head><title>t</title></head><body></body></html>')
|
|
||||||
body = soup.find(name='body')
|
|
||||||
body.insert(0, story)
|
|
||||||
return soup
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user