ndarville / newsdiffs

Automatic scraper that tracks changes in news articles over time.
Other
1 stars 0 forks source link

Parser for b.dk #5

Open ndarville opened 10 years ago

ndarville commented 10 years ago
ndarville commented 10 years ago
from baseparser import BaseParser
from BeautifulSoup import BeautifulSoup

class InformationParser(BaseParser):
    feeder_pat = '^http://www.b.dk/(nationalt|politiko|globalt)/'
    feeder_pages =  ['http://www.b.dk/nyhedsoversigt']

    def _parse(self, html):
        """Retrieve and serve the required fields to create an entry."""
        soup = BeautifulSoup(html,
            convertEntities=BeautifulSoup.HTML_ENTITIES,
            fromEncoding='utf-8')

        self.meta = soup.findAll('meta')
        self.title = soup.find('h1').getText()
        self.date = ""
        self.byline = soup.find('span', {'itemprop': 'author'}).next.getText()
        summary = soup.find('div', 'manchet').getText()
        content = soup.find('div', {'itemprop': 'articleBody'}.getText()
        self.body =  summary + content