mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Update The Atlantic
This commit is contained in:
parent
db47669c10
commit
db09bafd9e
@ -5,9 +5,14 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
'''
|
'''
|
||||||
theatlantic.com
|
theatlantic.com
|
||||||
'''
|
'''
|
||||||
import re
|
import html5lib
|
||||||
|
from lxml import html
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
|
||||||
|
def classes(classes):
|
||||||
|
q = frozenset(classes.split(' '))
|
||||||
|
return dict(attrs={'class':lambda x:x and frozenset(x.split()).intersection(q)})
|
||||||
|
|
||||||
class TheAtlantic(BasicNewsRecipe):
|
class TheAtlantic(BasicNewsRecipe):
|
||||||
|
|
||||||
title = 'The Atlantic'
|
title = 'The Atlantic'
|
||||||
@ -18,7 +23,7 @@ class TheAtlantic(BasicNewsRecipe):
|
|||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
{'attrs':{'class':['article-header', 'article-body', 'article-magazine', 'metadata', 'article-cover-content']}},
|
classes('article-header article-body article-magazine metadata article-cover-content lead-img'),
|
||||||
]
|
]
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
{'name': ['meta', 'link', 'noscript']},
|
{'name': ['meta', 'link', 'noscript']},
|
||||||
@ -26,12 +31,18 @@ class TheAtlantic(BasicNewsRecipe):
|
|||||||
{'attrs':{'class':lambda x: x and 'article-tools' in x}},
|
{'attrs':{'class':lambda x: x and 'article-tools' in x}},
|
||||||
{'src':lambda x:x and 'spotxchange.com' in x},
|
{'src':lambda x:x and 'spotxchange.com' in x},
|
||||||
]
|
]
|
||||||
|
remove_tags_after = classes('article-body')
|
||||||
|
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
remove_attributes = ['style']
|
remove_attributes = ['style']
|
||||||
preprocess_regexps = [
|
|
||||||
(re.compile(r'<script\b.+?</script>', re.DOTALL), lambda m: ''),
|
def get_browser(self):
|
||||||
(re.compile(r'^.*<html', re.DOTALL|re.IGNORECASE), lambda m: '<html'),
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
]
|
br.set_cookie('inEuropeanUnion', '0', '.theatlantic.com')
|
||||||
|
return br
|
||||||
|
|
||||||
|
def preprocess_raw_html(self, raw, url):
|
||||||
|
return html.tostring(html5lib.parse(raw, treebuilder='lxml', namespaceHTMLElements=False), method='html', encoding=unicode)
|
||||||
|
|
||||||
def print_version(self, url):
|
def print_version(self, url):
|
||||||
return url + '?single_page=true'
|
return url + '?single_page=true'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user