| 1 |
import re |
| 2 |
|
| 3 |
from calibre.ebooks.BeautifulSoup import Comment |
| 4 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 5 |
|
| 6 |
|
| 7 |
class BenchmarkPl(BasicNewsRecipe): |
| 8 |
title = 'Benchmark.pl' |
| 9 |
__author__ = 'fenuks' |
| 10 |
description = 'benchmark.pl, recenzje i testy sprzętu, aktualności, rankingi, sterowniki, porady, opinie' |
| 11 |
masthead_url = 'http://www.benchmark.pl/i/logo-footer.png' |
| 12 |
cover_url = 'http://www.benchmark.pl/i/logo-dark.png' |
| 13 |
category = 'IT' |
| 14 |
language = 'pl' |
| 15 |
oldest_article = 8 |
| 16 |
max_articles_per_feed = 100 |
| 17 |
extra_css = 'ul {list-style-type: none;}' |
| 18 |
no_stylesheets = True |
| 19 |
use_embedded_content = False |
| 20 |
preprocess_regexps = [ |
| 21 |
( |
| 22 |
re.compile( |
| 23 |
'<h3><span style="font-size: small;"> Zobacz poprzednie <a href="http://www.benchmark.pl/news/zestawienie/grupa_id/135">Opinie dnia:</a></span>.*</body>', # noqa: E501, RUF039 |
| 24 |
re.DOTALL | re.IGNORECASE, |
| 25 |
), |
| 26 |
lambda match: '</body>', |
| 27 |
), |
| 28 |
(re.compile(r'Więcej o .*?</ul>', re.DOTALL | re.IGNORECASE), lambda match: ''), |
| 29 |
] # noqa: RUF039 |
| 30 |
|
| 31 |
keep_only_tags = [dict(id=['articleHeader', 'articleGallery']), dict(name='div', attrs={'class': ['m_zwykly', 'gallery']}), dict(id='article')] |
| 32 |
remove_tags_after = dict(id='article') |
| 33 |
remove_tags = [ |
| 34 |
dict( |
| 35 |
name='div', |
| 36 |
attrs={ |
| 37 |
'class': [ |
| 38 |
'comments', |
| 39 |
'body', |
| 40 |
'kategoria', |
| 41 |
'socialize', |
| 42 |
'thumb', |
| 43 |
'panelOcenaObserwowane', |
| 44 |
'categoryNextToSocializeGallery', |
| 45 |
'breadcrumb', |
| 46 |
'footer', |
| 47 |
'moreTopics', |
| 48 |
] |
| 49 |
}, |
| 50 |
), |
| 51 |
dict(name='table', attrs={'background': 'http://www.benchmark.pl/uploads/backend_img/a/fotki_newsy/opinie_dnia/bg.png'}), |
| 52 |
dict(name='table', attrs={'width': '210', 'cellspacing': '1', 'cellpadding': '4', 'border': '0', 'align': 'right'}), |
| 53 |
] # noqa: E501 |
| 54 |
|
| 55 |
INDEX = 'http://www.benchmark.pl' |
| 56 |
feeds = [ |
| 57 |
('Aktualności', 'http://www.benchmark.pl/rss/aktualnosci-pliki.xml'), |
| 58 |
('Testy i recenzje', 'http://www.benchmark.pl/rss/testy-recenzje-minirecenzje.xml'), |
| 59 |
] |
| 60 |
|
| 61 |
def append_page(self, soup, appendtag): |
| 62 |
nexturl = soup.find(attrs={'class': 'next'}) |
| 63 |
while nexturl: |
| 64 |
soup2 = self.index_to_soup(nexturl['href']) |
| 65 |
nexturl = soup2.find(attrs={'class': 'next'}) |
| 66 |
pagetext = soup2.find(name='div', attrs={'class': 'body'}) |
| 67 |
tag = appendtag.find('div', attrs={'class': 'k_ster'}) |
| 68 |
if tag: |
| 69 |
tag.extract() |
| 70 |
comments = pagetext.findAll(text=lambda text: isinstance(text, Comment)) |
| 71 |
for comment in comments: |
| 72 |
comment.extract() |
| 73 |
pos = len(appendtag.contents) |
| 74 |
appendtag.insert(pos, pagetext) |
| 75 |
if appendtag.find('div', attrs={'class': 'k_ster'}): |
| 76 |
appendtag.find('div', attrs={'class': 'k_ster'}).extract() |
| 77 |
for r in appendtag.findAll(attrs={'class': 'changePage'}): |
| 78 |
r.extract() |
| 79 |
|
| 80 |
def preprocess_html(self, soup): |
| 81 |
self.append_page(soup, soup.body) |
| 82 |
for a in soup.findAll('a', href=True): |
| 83 |
if not a['href'].startswith('http'): |
| 84 |
a['href'] = self.INDEX + a['href'] |
| 85 |
for r in soup.findAll(attrs={'class': ['comments', 'body']}): |
| 86 |
r.extract() |
| 87 |
tag1 = soup.find(attrs={'class': 'inlineGallery'}) |
| 88 |
if tag1: |
| 89 |
for tag in tag1.findAll('li'): |
| 90 |
tag['style'] = 'float: left; margin-right: 10px;' |
| 91 |
tag1.findNext('p')['style'] = 'clear: both;' |
| 92 |
return soup |