mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Outlook Business Magazine
This commit is contained in:
parent
d380be1e1e
commit
8fcb834e4d
@ -18,53 +18,61 @@ class outlook(BasicNewsRecipe):
|
|||||||
remove_attributes = ['height', 'width', 'style']
|
remove_attributes = ['height', 'width', 'style']
|
||||||
ignore_duplicate_articles = {'url'}
|
ignore_duplicate_articles = {'url'}
|
||||||
masthead_url = 'https://imgnew.outlookindia.com/uploadimage/library/free_files/jpg/logo_2022_04_30_092331.jpg'
|
masthead_url = 'https://imgnew.outlookindia.com/uploadimage/library/free_files/jpg/logo_2022_04_30_092331.jpg'
|
||||||
resolve_internal_links = True
|
extra_css = '.author{font-size:small;}'
|
||||||
|
|
||||||
keep_only_tags = [classes('__story_detail')]
|
|
||||||
remove_tags = [
|
|
||||||
classes(
|
|
||||||
'social_sharing_article left_trending left-sticky __tag_links next_prev_stories downarrow uparrow more_from_author_links next prev'
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
soup = self.index_to_soup('https://business.outlookindia.com')
|
soup = self.index_to_soup('https://www.outlookbusiness.com/magazine/')
|
||||||
a = soup.find('a', href=lambda x: x and x.startswith('/magazine/issue/'))
|
div = soup.find('div', attrs={'class': 'SplWapper'})
|
||||||
url = a['href']
|
url = div.find('a', href=True)['href']
|
||||||
self.log('Downloading issue:', url)
|
self.cover_url = div.find('img', srcset=True)['srcset']
|
||||||
soup = self.index_to_soup('https://business.outlookindia.com' + url)
|
self.timefmt = '[' + self.tag_to_string(div.find('h6')) + ']'
|
||||||
cover = soup.find(**classes('listingPage_lead_story'))
|
soup = self.index_to_soup('https://www.outlookbusiness.com' + url)
|
||||||
self.cover_url = cover.find('img', attrs={'src': True})['src']
|
|
||||||
ans = []
|
ans = []
|
||||||
|
|
||||||
for h3 in soup.findAll(['h3', 'h4'],
|
for section in soup.findAll(**classes('category-banner-content')):
|
||||||
attrs={'class': 'tk-kepler-std-condensed-subhead'}):
|
p = section.find(
|
||||||
a = h3.find('a', href=lambda x: x)
|
'p',
|
||||||
url = a['href']
|
attrs={'class': lambda x: x and x.startswith('styled__Content')}
|
||||||
title = self.tag_to_string(a)
|
)
|
||||||
desc = ''
|
|
||||||
p = h3.find_next_sibling('p')
|
|
||||||
if p:
|
|
||||||
desc = self.tag_to_string(p)
|
desc = self.tag_to_string(p)
|
||||||
self.log('\t', title)
|
head = section.find(
|
||||||
self.log('\t', desc)
|
'p',
|
||||||
self.log('\t\t', url)
|
attrs={'class': lambda x: x and x.startswith('styled__Heading')}
|
||||||
ans.append({'title': title, 'url': url, 'description': desc})
|
)
|
||||||
|
title = self.tag_to_string(head)
|
||||||
|
a = p.findParent('a', href=True)['href']
|
||||||
|
if a.startswith('/'):
|
||||||
|
url = 'https://www.outlookbusiness.com' + a
|
||||||
|
self.log('\t', title, '\n\t', desc, '\n\t\t', url)
|
||||||
|
ans.append({'title': title, 'description': desc, 'url': url})
|
||||||
return [('Articles', ans)]
|
return [('Articles', ans)]
|
||||||
|
|
||||||
def preprocess_raw_html(self, raw, *a):
|
def preprocess_raw_html(self, raw, *a):
|
||||||
return raw
|
m = re.search('id="__NEXT_DATA__" type="application/json">', raw)
|
||||||
m = re.search('<!-- NewsArticle Schema -->.*?script.*?>', raw, flags=re.DOTALL)
|
raw = raw[m.start():]
|
||||||
raw = raw[m.end():].lstrip()
|
raw = raw.split('>', 1)[1]
|
||||||
data = json.JSONDecoder().raw_decode(raw)[0]
|
data = json.JSONDecoder().raw_decode(raw)[0]
|
||||||
title = data['headline']
|
data = data['props']['initialState']['dashboard']['ARTICLE_POST_DETAIL_API'][
|
||||||
body = data['articleBody']
|
'data']['article_data']
|
||||||
body = body.replace('\r\n', '<p>')
|
title = data['title']
|
||||||
author = ' and '.join(x['name'] for x in data['author'])
|
body = data['description']
|
||||||
image = desc = ''
|
cat = desc = image = author = ''
|
||||||
if data.get('image'):
|
if 'category_name' in data:
|
||||||
image = '<p><img src="{}">'.format(data['image']['url'])
|
try:
|
||||||
if data.get('description'):
|
cat = data['category_name']
|
||||||
desc = '<h2>' + data['description'] + '</h2>'
|
except Exception:
|
||||||
html = '<html><body><h1>' + title + '</h1>' + desc + '<h3>' + author + '</h3>' + image + '<p>' + body
|
cat = ''
|
||||||
|
if 'excerpt' in data:
|
||||||
|
desc = '<h4>' + data['excerpt'] + '</h4>'
|
||||||
|
if 'author' in data:
|
||||||
|
try:
|
||||||
|
author = data['author'][0]['name']
|
||||||
|
except Exception:
|
||||||
|
author = ''
|
||||||
|
if 'images' in data:
|
||||||
|
try:
|
||||||
|
image = '<p><img src="{}">'.format(data['images'][0]['image'])
|
||||||
|
except Exception:
|
||||||
|
image = ''
|
||||||
|
html = '<html><body>' + cat + '<h1>' + title + '</h1>' + desc + '<div class="author">' + author + '</div>' + image + body
|
||||||
return html
|
return html
|
||||||
|
Loading…
x
Reference in New Issue
Block a user