iter_torrent wokay, unit fail
This commit is contained in:
parent
a55a241ffb
commit
0cc2458513
2 changed files with 31 additions and 26 deletions
|
|
@ -26,6 +26,8 @@ __all__ = ['PiratebayBrowser']
|
||||||
|
|
||||||
|
|
||||||
class PiratebayBrowser(BaseBrowser):
|
class PiratebayBrowser(BaseBrowser):
|
||||||
|
PROTOCOL = 'https'
|
||||||
|
USER_AGENT = BaseBrowser.USER_AGENTS['wget']
|
||||||
PAGES = {'https://thepiratebay.org' : IndexPage,
|
PAGES = {'https://thepiratebay.org' : IndexPage,
|
||||||
'https://thepiratebay.org/search/.*/0/7/0' : TorrentsPage,
|
'https://thepiratebay.org/search/.*/0/7/0' : TorrentsPage,
|
||||||
#'https://thepiratebay.org/torrent/.*' : TorrentPage
|
#'https://thepiratebay.org/torrent/.*' : TorrentPage
|
||||||
|
|
@ -34,7 +36,7 @@ class PiratebayBrowser(BaseBrowser):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
#self.DOMAIN = domain
|
#self.DOMAIN = domain
|
||||||
#self.PROTOCOL = protocol
|
#self.PROTOCOL = protocol
|
||||||
self.PAGES = {}
|
#self.PAGES = {}
|
||||||
#for key, value in PiratebayBrowser.PAGES.iteritems():
|
#for key, value in PiratebayBrowser.PAGES.iteritems():
|
||||||
# self.PAGES[key % domain] = value
|
# self.PAGES[key % domain] = value
|
||||||
|
|
||||||
|
|
@ -57,7 +59,7 @@ class PiratebayBrowser(BaseBrowser):
|
||||||
|
|
||||||
def iter_torrents(self, pattern):
|
def iter_torrents(self, pattern):
|
||||||
#self.location(self.buildurl('/torrents.php', searchstr=pattern))
|
#self.location(self.buildurl('/torrents.php', searchstr=pattern))
|
||||||
self.location('https://thepiratebay.org/search/%s/0/7/0' % pattern)
|
self.location('https://thepiratebay.org/search/%s/0/7/0' % pattern, '')
|
||||||
|
|
||||||
assert self.is_on_page(TorrentsPage)
|
assert self.is_on_page(TorrentsPage)
|
||||||
return self.page.iter_torrents()
|
return self.page.iter_torrents()
|
||||||
|
|
|
||||||
|
|
@ -50,30 +50,33 @@ class TorrentsPage(BasePage):
|
||||||
raise Exception('You''re in serious troubles!')
|
raise Exception('You''re in serious troubles!')
|
||||||
else:
|
else:
|
||||||
for tr in table.getiterator('tr'):
|
for tr in table.getiterator('tr'):
|
||||||
td = tr.getchildren()[1]
|
if tr.get('class','') != "header":
|
||||||
div = td.getchildren()[0]
|
td = tr.getchildren()[1]
|
||||||
link = div.find('a').attrib('href')
|
div = td.getchildren()[0]
|
||||||
title = div.find('a').text
|
link = div.find('a').attrib['href']
|
||||||
idt = link.split('/')[2]
|
title = div.find('a').text
|
||||||
|
idt = link.split('/')[2]
|
||||||
|
|
||||||
a = td.getchildren()[1]
|
a = td.getchildren()[1]
|
||||||
url = a.attrib('href')
|
url = a.attrib['href']
|
||||||
|
|
||||||
size = td.find('font').text.split(',')[1]
|
size = td.find('font').text.split(',')[1]
|
||||||
size = size.split(' ')[2]
|
size = size.split(' ')[2]
|
||||||
u = size[-3:].replace('i','')
|
u = size[-3:].replace('i','')
|
||||||
size = size[:-3]
|
print "u:"+u
|
||||||
|
size = size[:-3]
|
||||||
|
print 'size:'+size
|
||||||
|
|
||||||
seed = tr.getchildren()[2].text
|
seed = tr.getchildren()[2].text
|
||||||
leech = tr.getchildren()[3].text
|
leech = tr.getchildren()[3].text
|
||||||
|
|
||||||
torrent = Torrent(idt,
|
torrent = Torrent(idt,
|
||||||
title,
|
title,
|
||||||
url=url,
|
url=url,
|
||||||
size=size,
|
size=self.unit(size.replace('.',','),u),
|
||||||
seeders=seeders,
|
seeders=int(seed),
|
||||||
leechers=leechers)
|
leechers=int(leech))
|
||||||
yield torrent
|
yield torrent
|
||||||
|
|
||||||
def get_torrent(self, id):
|
def get_torrent(self, id):
|
||||||
table = self.document.getroot().cssselect('div.thin')
|
table = self.document.getroot().cssselect('div.thin')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue