| 1 |
#!/usr/bin/env python |
| 2 |
from calibre.web.feeds.news import BasicNewsRecipe, classes |
| 3 |
|
| 4 |
|
| 5 |
class RevistaMuyInteresante(BasicNewsRecipe): |
| 6 |
title = 'Revista Muy Interesante' |
| 7 |
__author__ = 'unkn0wn' |
| 8 |
description = 'Revista Muy Interesante, es un sitio con información sobre ciencia, tecnología, historia, sociedad, medio ambiente, etc.' |
| 9 |
language = 'es' |
| 10 |
encoding = 'utf-8' |
| 11 |
no_stylesheets = True |
| 12 |
remove_javascript = True |
| 13 |
remove_attributes = ['style', 'height', 'width'] |
| 14 |
ignore_duplicate_articles = {'url'} |
| 15 |
masthead_url = 'https://www.muyinteresante.com/static/img/logo_web.svg' |
| 16 |
resolve_internal_links = True |
| 17 |
|
| 18 |
def get_cover_url(self): |
| 19 |
soup = self.index_to_soup('https://www.magzter.com/ES/Zinet-Media-Global/Muy-Interesante-Espa%C3%B1a/Science/1806044') |
| 20 |
return soup.find('img', id=lambda s: s and 'mgd__lhd__cover' in s.split())['src'] |
| 21 |
|
| 22 |
extra_css = ''' |
| 23 |
.c-detail__bar, .c-detail__author, .c-detail__media__txt { font-size:small; } |
| 24 |
.default-epigraph { font-style:italic; } |
| 25 |
''' |
| 26 |
|
| 27 |
keep_only_tags = [dict(name='article', attrs={'class': 'c-detail'})] |
| 28 |
|
| 29 |
remove_tags = [dict(name=['aside', 'svg', 'script']), classes('c-detail__share')] |
| 30 |
|
| 31 |
def preprocess_html(self, soup): |
| 32 |
au = soup.find(**classes('c-detail__author')) |
| 33 |
if au: |
| 34 |
for p in au.findAll('p'): |
| 35 |
p.name = 'div' |
| 36 |
for h in soup.findAll(['h2', 'h3']): |
| 37 |
h.name = 'h4' |
| 38 |
return soup |
| 39 |
|
| 40 |
def parse_index(self): |
| 41 |
soup = self.index_to_soup('https://www.muyinteresante.com/') |
| 42 |
ans = [] |
| 43 |
for articles in soup.findAll('article'): |
| 44 |
a = articles.find('a', attrs={'class': 'page-link', 'href': True}) |
| 45 |
if not a: |
| 46 |
continue |
| 47 |
title = self.tag_to_string(a) |
| 48 |
url = a['href'] |
| 49 |
desc = '' |
| 50 |
info = articles.find(**classes('c-article__info_content')) |
| 51 |
if info: |
| 52 |
desc = self.tag_to_string(info) |
| 53 |
self.log('\t', title, '\n\t', desc, '\n\t\t', url) |
| 54 |
ans.append({'title': title, 'url': url, 'description': desc}) |
| 55 |
return [('Articles', ans)] |