home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_280 / el_pais_babelia.recipe < prev    next >
Text File  |  2011-09-09  |  2KB  |  50 lines

  1. from calibre.web.feeds.news import BasicNewsRecipe
  2.  
  3. class ElPaisBabelia(BasicNewsRecipe):
  4.  
  5.     title      = 'El Pais Babelia'
  6.     __author__ = 'oneillpt'
  7.     description = 'El Pais Babelia'
  8.     INDEX = 'http://www.elpais.com/suple/babelia/'
  9.     language = 'es'
  10.  
  11.     remove_tags_before = dict(name='div', attrs={'class':'estructura_2col'})
  12.     keep_tags = [dict(name='div', attrs={'class':'estructura_2col'})]
  13.     remove_tags = [dict(name='div', attrs={'class':'votos estirar'}),
  14.         dict(name='div', attrs={'id':'utilidades'}),
  15.         dict(name='div', attrs={'class':'info_relacionada'}),
  16.         dict(name='div', attrs={'class':'mod_apoyo'}),
  17.         dict(name='div', attrs={'class':'contorno_f'}),
  18.         dict(name='div', attrs={'class':'pestanias'}),
  19.         dict(name='div', attrs={'class':'otros_webs'}),
  20.         dict(name='div', attrs={'id':'pie'})
  21.         ]
  22.     #no_stylesheets = True
  23.     remove_javascript     = True
  24.  
  25.     def parse_index(self):
  26.         articles = []
  27.         soup = self.index_to_soup(self.INDEX)
  28.         feeds = []
  29.         for section in soup.findAll('div', attrs={'class':'contenedor_nuevo'}):
  30.             section_title = self.tag_to_string(section.find('h1'))
  31.             articles = []
  32.             for post in section.findAll('a', href=True):
  33.                 url = post['href']
  34.                 if url.startswith('/'):
  35.                   url = 'http://www.elpais.es'+url
  36.                   title = self.tag_to_string(post)
  37.                   if str(post).find('class=') > 0:
  38.                     klass = post['class']
  39.                     if klass != "":
  40.                       self.log()
  41.                       self.log('--> post:  ', post)
  42.                       self.log('--> url:   ', url)
  43.                       self.log('--> title: ', title)
  44.                       self.log('--> class: ', klass)
  45.                       articles.append({'title':title, 'url':url})
  46.             if articles:
  47.                 feeds.append((section_title, articles))
  48.         return feeds
  49.  
  50.