| 1 |
#!/usr/bin/env python |
| 2 |
# vim:fileencoding=utf-8 |
| 3 |
from __future__ import absolute_import, division, print_function, unicode_literals |
| 4 |
|
| 5 |
__license__ = 'GPL v3' |
| 6 |
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>' |
| 7 |
|
| 8 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 9 |
|
| 10 |
|
| 11 |
class EntrepeneurMagRecipe(BasicNewsRecipe): |
| 12 |
__author__ = 'Kovid Goyal' |
| 13 |
language = 'en' |
| 14 |
|
| 15 |
title = 'Entrepeneur Magazine' |
| 16 |
publisher = 'Entrepreneur Media, Inc' |
| 17 |
category = 'Business' |
| 18 |
description = 'Online magazine on business, small business, management and economy' |
| 19 |
|
| 20 |
encoding = 'utf-8' |
| 21 |
|
| 22 |
no_stylesheets = True |
| 23 |
remove_javascript = True |
| 24 |
|
| 25 |
keep_only_tags = [ |
| 26 |
dict(name='article', id=lambda x: x and x.startswith('post-')), |
| 27 |
] |
| 28 |
remove_tags = [ |
| 29 |
dict(attrs={'class': ['related-content', 'icon']}), |
| 30 |
] |
| 31 |
remove_attributes = ['style'] |
| 32 |
|
| 33 |
INDEX = 'https://www.entrepreneur.com' |
| 34 |
|
| 35 |
def parse_index(self): |
| 36 |
soup = self.index_to_soup(self.INDEX + '/latest') |
| 37 |
articles = [] |
| 38 |
for h3 in soup.findAll('h3'): |
| 39 |
a = h3.find('a') |
| 40 |
if a and a.get('href'): |
| 41 |
url = a['href'] |
| 42 |
title = self.tag_to_string(h3) |
| 43 |
desc = '' |
| 44 |
if a.next_sibling and a.next_sibling.name == 'p': |
| 45 |
desc = self.tag_to_string(a.next_sibling) |
| 46 |
articles.append({'title': title, 'url': url, 'description': desc}) |
| 47 |
self.log(title, url) |
| 48 |
return [('Articles', articles)] |
| 49 |
|
| 50 |
def preprocess_html(self, soup): |
| 51 |
for img in soup.findAll('img', attrs={'data-src': True}): |
| 52 |
img['src'] = img['data-src'] |
| 53 |
return soup |