mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix recipe cover_url for Foreign Affairs, Nature
This commit is contained in:
parent
69ca92de92
commit
c1634e6df5
@ -6,13 +6,7 @@ import html5lib
|
|||||||
import mechanize
|
import mechanize
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
|
||||||
from calibre.web.feeds.news import BasicNewsRecipe
|
from calibre.web.feeds.news import BasicNewsRecipe, classes
|
||||||
|
|
||||||
|
|
||||||
def classes(classes):
|
|
||||||
q = frozenset(classes.split(' '))
|
|
||||||
return dict(attrs={
|
|
||||||
'class': lambda x: x and frozenset(x.split()).intersection(q)})
|
|
||||||
|
|
||||||
|
|
||||||
def as_article(source, log):
|
def as_article(source, log):
|
||||||
@ -155,9 +149,14 @@ class ForeignAffairsRecipe(BasicNewsRecipe):
|
|||||||
self.timefmt = u' [%s]' % date
|
self.timefmt = u' [%s]' % date
|
||||||
link = soup.find('link', rel='canonical', href=True)['href']
|
link = soup.find('link', rel='canonical', href=True)['href']
|
||||||
year, volnum, issue_vol = link.split('/')[-3:]
|
year, volnum, issue_vol = link.split('/')[-3:]
|
||||||
self.cover_url = soup.find(**classes('subscribe-callout-image'))['srcset'].split()[-3]
|
self.cover_url = re.sub(
|
||||||
self.cover_url = self.cover_url.split('?')[0]
|
r"_webp_issue_small_\dx",
|
||||||
self.cover_url = self.cover_url.replace('_webp_issue_small_2x', '_webp_issue_large_2x')
|
"_webp_issue_large_2x",
|
||||||
|
soup.find(class_="subscribe-callout-image")["srcset"]
|
||||||
|
.split(",")[0]
|
||||||
|
.strip()
|
||||||
|
.split(" ")[0],
|
||||||
|
)
|
||||||
|
|
||||||
cls = soup.find('body')['class']
|
cls = soup.find('body')['class']
|
||||||
if isinstance(cls, (list, tuple)):
|
if isinstance(cls, (list, tuple)):
|
||||||
|
@ -51,7 +51,7 @@ class Nature(BasicNewsRecipe):
|
|||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
soup = self.index_to_soup(BASE + '/nature/current-issue')
|
soup = self.index_to_soup(BASE + '/nature/current-issue')
|
||||||
self.cover_url = 'https:' + soup.find(
|
self.cover_url = soup.find(
|
||||||
'img', attrs={'data-test': check_words('issue-cover-image')}
|
'img', attrs={'data-test': check_words('issue-cover-image')}
|
||||||
)['src']
|
)['src']
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user