Beispiel #1
0
 def parse(self, response):
     titulo = response.selector.xpath('/html/body/div[1]/div[2]/section/div[4]/article/div[1]/h1').extract()
     fecha = response.selector.xpath('/html/body/div[1]/div[2]/section/div[4]/article/div[1]/div').extract()
     seccion = response.selector.xpath('/html/body/div[1]/div[2]/section/div[4]/article/div[1]/h3[1]/a[2]').extract()
     pagename = '/home/federico/Desktop/corpus_inil/crawler/crawler/crawlinil/datos_crhoy/' + str(random.randint(1,1000))
     titulo = BeautifulSoup(titulo[0], 'lxml').text
     titulo = titulo.rstrip('\n')
     fecha = BeautifulSoup(fecha[0], 'lxml').text
     fecha = re.findall('\w*\s\w*,\s\w*', fecha)[0]
     seccion = BeautifulSoup(seccion[0], 'lxml').text
     #macrosecciones
     if seccion in ['Fútbol', 'Atletismo', 'Baloncesto', 'Tennis', 'Motores', 'Natación', 'Ciclismo', 'Surf', 'Voleibol', 'Otros', 'Destino Rusia']:
         seccion = 'Deportes'
     if seccion in ['Clima', 'Educación', 'Gobierno', 'Política', 'Salud', 'Transportes', 'Servicios']:
         seccion = 'Nacionales'
     if seccion in = ['Sucesos']:
         seccion = 'Sucesos'
     if seccion in = ['Columnas'. 'Especialistas', 'Lector opina', 'Aclaraciones']:
         seccion = 'Opinión'
def downloadEpisode(episode):
    search_text = "%s %s" % (episode.season.serie.name, episode.num)
    
    url = 'http://thepiratebay.org/search/%s/0/7/0' % urllib.quote(search_text)
    search = urllib2.urlopen( url ).read()
    torrents = BeautifulSoup(search).findAll('td')
    if len(torrents) > 1:
        torrent = torrents[1]
        link = BeautifulSoup("<html><body>%s</body></html>" % torrent).findAll('a')[1]
        link = re.search('href="(.*?)"', str(link)).group(1)
        
        if link.rstrip():
            download = model.Download()
            download.torrentFile = link
            download.episode = episode
        
            model.Session.add( download )
        
            fp = open( os.path.join( getOption('download.torrent.folder'), os.path.basename(link) ) , 'w')
            fp.write( urllib2.urlopen( link ).read() )
            fp.close()