mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
fix recipe after website redesign
This commit is contained in:
parent
714bc11820
commit
b62b38fc25
@ -8,6 +8,7 @@ __copyright__ = '2015 Michael Marotta <mikefm at gmail.net>'
|
|||||||
technologyreview.com
|
technologyreview.com
|
||||||
'''
|
'''
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def absurl(x):
|
def absurl(x):
|
||||||
@ -37,24 +38,40 @@ class MitTechnologyReview(BasicNewsRecipe):
|
|||||||
tags = 'news, technology, science'
|
tags = 'news, technology, science'
|
||||||
no_stylesheets = True
|
no_stylesheets = True
|
||||||
|
|
||||||
|
"""
|
||||||
|
regex for class names
|
||||||
|
"""
|
||||||
|
articleHeaderRegex= '^.*contentHeader__wrapper.*$'
|
||||||
|
editorLetterHeaderRegex = "^.*contentHeader--vertical__wrapper.*$"
|
||||||
|
articleContentRegex = "^.*contentbody__wrapper.*$"
|
||||||
|
imagePlaceHolderRegex = "^.*image__placeholder.*$"
|
||||||
|
advertisementRegex = "^.*sliderAd__wrapper.*$"
|
||||||
|
|
||||||
keep_only_tags = [
|
keep_only_tags = [
|
||||||
classes(
|
dict(name='header', attrs={'class': re.compile(editorLetterHeaderRegex, re.IGNORECASE)}),
|
||||||
'article-topper__topic article-topper__title article-topper__media-wrap article-body__content storyContent'),
|
dict(name='header', attrs={'class': re.compile(articleHeaderRegex, re.IGNORECASE)}),
|
||||||
|
dict(name='div', attrs={'class': re.compile(articleContentRegex, re.IGNORECASE)})
|
||||||
]
|
]
|
||||||
remove_tags = [
|
remove_tags = [
|
||||||
classes('l-article-list signup-wrapper'),
|
dict(name="aside"),
|
||||||
dict(name="svg")
|
dict(name="svg"),
|
||||||
|
dict(name="blockquote"),
|
||||||
|
dict(name="img", attrs={'class': re.compile(imagePlaceHolderRegex, re.IGNORECASE)}),
|
||||||
|
dict(name="div", attrs={'class': re.compile(advertisementRegex, re.IGNORECASE)}),
|
||||||
]
|
]
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
soup = self.index_to_soup(self.INDEX)
|
soup = self.index_to_soup(self.INDEX)
|
||||||
# find cover
|
# find cover
|
||||||
self.cover_url = absurl(soup.find(
|
self.cover_url = absurl(soup.find(
|
||||||
'a', attrs={'class': 'magazine-topper__cover'}).find('img', src=True)['src'])
|
"div", attrs={"class":lambda name: name.startswith("magazineHero__image") if name else False}).find(
|
||||||
|
"img",
|
||||||
|
src=True
|
||||||
|
)['src'])
|
||||||
# parse articles
|
# parse articles
|
||||||
current_articles = []
|
current_articles = []
|
||||||
for div in soup.findAll(attrs={'class': lambda x: x in
|
classNamePrefixes = ["magazineHero__letter--", "teaserItem__title", "teaserItem--aside__title"]
|
||||||
'magazine-topper__title magazine-features-item__top-title magazine-features-item-title author-tz__title feed-tz__title'.split()}):
|
for div in soup.findAll(attrs={'class': lambda x: any(x.startswith(prefix) for prefix in classNamePrefixes) if x else False}):
|
||||||
a = div.find('a', href=True)
|
a = div.find('a', href=True)
|
||||||
title = self.tag_to_string(a).strip()
|
title = self.tag_to_string(a).strip()
|
||||||
href = absurl(a['href'])
|
href = absurl(a['href'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user