| 1 |
#!/usr/bin/env python |
| 2 |
from calibre.web.feeds.recipes import BasicNewsRecipe |
| 3 |
|
| 4 |
|
| 5 |
class Volkskrant(BasicNewsRecipe): |
| 6 |
title = 'Revista 22' |
| 7 |
__author__ = 'Cristi Ghera' |
| 8 |
max_articles_per_feed = 100 |
| 9 |
description = 'Revista 22' |
| 10 |
needs_subscription = False |
| 11 |
language = 'ro' |
| 12 |
country = 'RO' |
| 13 |
category = 'news, politics, Romania' |
| 14 |
resolve_internal_links = True |
| 15 |
remove_tags_before = {'class': 'col-span-8'} |
| 16 |
remove_tags_after = {'class': 'col-span-8'} |
| 17 |
remove_tags = [ |
| 18 |
dict( |
| 19 |
attrs={ |
| 20 |
'class': [ |
| 21 |
'icons', |
| 22 |
'float-left', |
| 23 |
'samesection', |
| 24 |
] |
| 25 |
} |
| 26 |
), |
| 27 |
dict(name=['div'], attrs={'class': ['mb-2']}), |
| 28 |
dict(id=['comments']), |
| 29 |
dict(name=['script', 'noscript', 'style']), |
| 30 |
] |
| 31 |
remove_attributes = ['class', 'id', 'name', 'style'] |
| 32 |
encoding = 'utf-8' |
| 33 |
no_stylesheets = True |
| 34 |
ignore_duplicate_articles = {'url'} |
| 35 |
|
| 36 |
def parse_index(self): |
| 37 |
soup = self.index_to_soup('https://revista22.ro') |
| 38 |
url = soup.find('div', attrs={'class': 'uppercase'}).find('a').attrs['href'] |
| 39 |
if url[0] == '/': |
| 40 |
url = 'https://revista22.ro' + url |
| 41 |
soup = self.index_to_soup(url) |
| 42 |
main_container = soup.find('div', attrs={'class': 'col-span-8'}) |
| 43 |
containers = main_container.findAll(attrs={'class': 'mb-4'}) |
| 44 |
articles = [] |
| 45 |
for container in containers: |
| 46 |
if 'pb-4' not in container.attrs['class']: |
| 47 |
continue |
| 48 |
a = container.find('a') |
| 49 |
url = a['href'] |
| 50 |
if url[0] == '/': |
| 51 |
url = 'https://revista22.ro' + url |
| 52 |
article_title = self.tag_to_string(a.find('h3')).strip() |
| 53 |
author = self.tag_to_string(container.find('span', attrs={'class': 'text-red'})).strip() |
| 54 |
summary = self.tag_to_string(container.find('p')).strip() |
| 55 |
pubdate = self.tag_to_string(a.find('span')) |
| 56 |
description = author + ' - ' + summary |
| 57 |
articles.append(dict(title=article_title, url=url, date=pubdate, description=description, content='')) |
| 58 |
|
| 59 |
sections = [('Numărul curent', articles)] |
| 60 |
return sections |