View Single Post
Old 08-29-2018, 02:50 PM   #2
lui1
Enthusiast
lui1 began at the beginning.
 
Posts: 36
Karma: 10
Join Date: Dec 2017
Location: Los Angeles, CA
Device: Smart Phone
I think the moved the 'sigin in form' to http://fortune.com/sitemap/. Try this.

Fortune Magazine Recipe
Code:
from calibre.web.feeds.recipes import BasicNewsRecipe


def classes(classes):
    q = frozenset(classes.split(' '))
    return dict(attrs={
        'class': lambda x: x and frozenset(x.split()).intersection(q)})


class Fortune(BasicNewsRecipe):

    title = 'Fortune Magazine'
    __author__ = 'Rick Shang'

    description = 'FORTUNE is a global business magazine that has been revered in its content and credibility since 1930. FORTUNE covers the entire field of business, including specific companies and business trends, prominent business leaders, and new ideas shaping the global marketplace.'  # noqa
    language = 'en'
    category = 'news'
    encoding = 'UTF-8'
    keep_only_tags = [
            dict(name='h1', attrs={'class': lambda x: x and 'headline' in x}),
            classes('lead-media author'),
            dict(id='article-body'),
    ]

    no_javascript = True
    no_stylesheets = True
    needs_subscription = 'optional'

    def get_browser(self):
        br = BasicNewsRecipe.get_browser(self)
        if self.username and self.password:
            br.open('http://fortune.com/sitemap/')
            br.select_form(id='sign-in-form')
            br['username'] = self.username
            br['password'] = self.password
            br.submit()
        return br

    def parse_index(self):
        articles = []

        # Go to the latestissue
        soup = self.index_to_soup('http://fortune.com/section/magazine/')
        articles = []

        for i, article in enumerate(soup.findAll('article', attrs={'class': lambda x: x and 'type-article' in x.split()})):
            div = article.find('div', attrs={'class': lambda x: x and 'article-info' in x.split()})
            a = div.find('a', href=True)
            url = a['href']
            if url.startswith('/'):
                url = 'http://fortune.com' + url
            title = self.tag_to_string(a)
            ai = div.find('div', attrs={'class': lambda x: x and 'article-info-extended' in x.split()})
            desc = ''
            if ai:
                desc = self.tag_to_string(desc)
            self.log('Article:', title, 'at', url)
            articles.append({'title': title, 'url': url, 'description': desc})
        return [('Articles', articles)]
lui1 is offline   Reply With Quote