mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Denver Post
Fixes #1587423 [Denver Post will not load content](https://bugs.launchpad.net/calibre/+bug/1587423)
This commit is contained in:
parent
f4b6ca4b27
commit
55aca490a4
@ -1,26 +1,33 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# vim:fileencoding=utf-8
|
||||||
|
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
from __future__ import (unicode_literals, division, absolute_import,
|
||||||
|
print_function)
|
||||||
|
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulSoup
|
|
||||||
|
def classes(classes):
|
||||||
|
q = frozenset(classes.split(' '))
|
||||||
|
return dict(attrs={
|
||||||
|
'class': lambda x: x and frozenset(x.split()).intersection(q)})
|
||||||
|
|
||||||
class DenverPost(BasicNewsRecipe):
|
class DenverPost(BasicNewsRecipe):
|
||||||
title = u'Denver Post'
|
title = u'Denver Post'
|
||||||
language = 'en'
|
language = 'en'
|
||||||
__author__ = 'Krittika Goyal'
|
__author__ = 'Kovid Goyal'
|
||||||
oldest_article = 1 # days
|
oldest_article = 1 # days
|
||||||
max_articles_per_feed = 20
|
max_articles_per_feed = 20
|
||||||
|
|
||||||
conversion_options = {'linearize_tables':True}
|
|
||||||
|
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
#remove_tags_before = dict(name='h1', attrs={'class':'heading'})
|
use_embedded_content = False
|
||||||
#remove_tags_after = dict(name='td', attrs={'class':'newptool1'})
|
keep_only_tags = [
|
||||||
|
dict(name='h1'),
|
||||||
|
classes('subheadline byline header-features article-body'),
|
||||||
|
]
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
dict(name='iframe'),
|
classes('related'),
|
||||||
dict(name='img', src=lambda x: not x or '/tracking/' in x),
|
dict(attrs={'data-config-video-id':True}),
|
||||||
dict(name='span', attrs={'fd-id':True}),
|
|
||||||
dict(name='div', attrs={'class':['articleOptions', 'articlePosition2']}),
|
|
||||||
#dict(name='div', attrs={'id':['qrformdiv', 'inSection', 'alpha-inner']}),
|
|
||||||
#dict(name='ul', attrs={'class':'article-tools'}),
|
|
||||||
#dict(name='ul', attrs={'class':'articleTools'}),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
feeds = [
|
feeds = [
|
||||||
@ -40,18 +47,8 @@ class DenverPost(BasicNewsRecipe):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def preprocess_html(self, soup):
|
def preprocess_html(self, soup):
|
||||||
story = soup.find(name='td', attrs={'class':'articleBox'})
|
for img in soup.findAll('img', attrs={'data-src':True}):
|
||||||
#td = heading.findParent(name='td')
|
img['src'] = img['data-src']
|
||||||
#td.extract()
|
del img['height']
|
||||||
story.extract()
|
del img['width']
|
||||||
soup = BeautifulSoup('<html><head><title>t</title></head><body></body></html>')
|
|
||||||
body = soup.find(name='body')
|
|
||||||
body.insert(0, story)
|
|
||||||
story.name = 'div'
|
|
||||||
|
|
||||||
for img in soup.findAll(name='img', style='visibility:hidden;'):
|
|
||||||
del img['style']
|
|
||||||
|
|
||||||
for div in soup.findAll(id='caption', style=True):
|
|
||||||
del div['style']
|
|
||||||
return soup
|
return soup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user