| 1 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 2 |
|
| 3 |
|
| 4 |
class Cracked(BasicNewsRecipe): |
| 5 |
title = 'Cracked.com' |
| 6 |
__author__ = 'UnWeave' |
| 7 |
language = 'en' |
| 8 |
description = "America's Only HumorSite since 1958" |
| 9 |
publisher = 'Cracked' |
| 10 |
category = 'comedy, lists' |
| 11 |
oldest_article = 3 # days |
| 12 |
max_articles_per_feed = 100 |
| 13 |
no_stylesheets = True |
| 14 |
encoding = 'utf-8' |
| 15 |
remove_javascript = True |
| 16 |
use_embedded_content = False |
| 17 |
recursions = 11 |
| 18 |
remove_attributes = ['size', 'style'] |
| 19 |
|
| 20 |
feeds = [('Articles', 'http://feeds.feedburner.com/CrackedRSS/')] |
| 21 |
|
| 22 |
conversion_options = {'comment': description, 'tags': category, 'publisher': publisher, 'language': language} |
| 23 |
|
| 24 |
keep_only_tags = [ |
| 25 |
dict( |
| 26 |
name='div', |
| 27 |
attrs={ |
| 28 |
'class': [ |
| 29 |
'content-content', |
| 30 |
'contentWrapper', |
| 31 |
'content-header', |
| 32 |
] |
| 33 |
}, |
| 34 |
), |
| 35 |
dict( |
| 36 |
name='article', |
| 37 |
attrs={ |
| 38 |
'class': [ |
| 39 |
'module article dropShadowBottomCurved', |
| 40 |
'module blog dropShadowBottomCurved', |
| 41 |
] |
| 42 |
}, |
| 43 |
), |
| 44 |
] |
| 45 |
|
| 46 |
remove_tags = [ |
| 47 |
dict(name='section', attrs={'class': ['socialTools', 'quickFixModule', 'continue-reading']}), |
| 48 |
dict(attrs={'class': ['socialShareAfterContent', 'socialShareModule', 'continue-reading', 'social-share-bottom list-inline']}), |
| 49 |
dict( |
| 50 |
name='div', |
| 51 |
attrs={'id': ['relatedArticle', 'content-card-top', 'recommendedForYourPleasure', 'navbar', 'flashbackModuleWrap', 'moreRecommendedArticles']}, |
| 52 |
), |
| 53 |
dict( |
| 54 |
name='div', |
| 55 |
attrs={ |
| 56 |
'class': [ |
| 57 |
'comments-wrap', |
| 58 |
'container continue-reading', |
| 59 |
'row breadcrumbs-wrapper', |
| 60 |
'btn-social-favorites col', |
| 61 |
'hidden-social col', |
| 62 |
'ajax-loader comments-loader-bottom', |
| 63 |
'flashback-module-new', |
| 64 |
'card-md-list card-sm-list card-xs-list', |
| 65 |
'popular-module card-md-list card-sm-list card-xs-list', |
| 66 |
'col-md-12 list-title', |
| 67 |
'content-cards d-flex flex-wrap', |
| 68 |
'google-plus btn btn-social', |
| 69 |
'twitter btn btn-social', |
| 70 |
'facebook btn btn-social', |
| 71 |
'row social-share-top-wrapper', |
| 72 |
] |
| 73 |
}, |
| 74 |
), |
| 75 |
dict(name='h4', attrs={'class': ['mobile-ad-label']}), |
| 76 |
dict(name='ul', attrs={'id': ['breadcrumbs', 'socialShare']}), |
| 77 |
dict(name='ul', attrs={'class': ['list-unstyled offcanvas-sections']}), |
| 78 |
dict(name='div', attrs={'class': ['bannerAd hidden-sm hidden-md hidden-lg introAd']}), |
| 79 |
] |
| 80 |
|
| 81 |
def is_link_wanted(self, url, a): |
| 82 |
return a['class'] == 'next' and a.findParent('nav', attrs={'class': 'PaginationContent'}) is not None |
| 83 |
|
| 84 |
def preprocess_html(self, soup): |
| 85 |
for img in soup.findAll('img', attrs={'data-img': True}): |
| 86 |
img['src'] = img['data-img'] |
| 87 |
for img in soup.findAll('img', attrs={'data-original': True}): |
| 88 |
img['src'] = img['data-original'] |
| 89 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 90 |
img['src'] = img['data-src'] |
| 91 |
return soup |
| 92 |
|
| 93 |
def postprocess_html(self, soup, first_fetch): |
| 94 |
for div in soup.findAll(attrs={'class': 'PaginationContent'}): |
| 95 |
div.extract() |
| 96 |
if not first_fetch: |
| 97 |
for div in soup.findAll(attrs={'class': 'meta'}): |
| 98 |
div.extract() |
| 99 |
|
| 100 |
return soup |