-
Notifications
You must be signed in to change notification settings - Fork 194
/
pirateBayCrawl.py
32 lines (27 loc) · 1.17 KB
/
pirateBayCrawl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: Adastra
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import HtmlXPathSelector
from scrapy.item import Item, Field
class Torrent(Item):
url = Field()
tipo = Field()
torrentLink = Field()
size = Field()
description = Field()
class PirateBaySpider(CrawlSpider):
name = 'thepiratebay.sx'
allowed_domains = ['thepiratebay.sx']
start_urls = ['http://thepiratebay.sx/browse']
rules = [Rule(SgmlLinkExtractor(allow=['/\d+']), 'parse_torrent')]
def parse_torrent(self, response):
x = HtmlXPathSelector(response)
torrent = Torrent()
torrent['url'] = response.url
torrent['tipo'] = x.select('//*[@id="searchResult"]/tr[1]/td[1]/center/a[2]//text()').extract()
torrent['torrentLink'] = x.select('//*[@id="searchResult"]/tr[1]/td[2]/a[2]/@href').extract()
torrent['description'] = x.select('//*[@id="searchResult"]/tr[1]/td[2]/div/a/@title').extract()
torrent['size'] = x.select('//*[@id="searchResult"]/tr[1]/td[2]/font/text()[2]').extract()
return torrent