usr bin env python import urllib2 import urlparse import BeautifulSoup

 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
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python
import urllib2
import urlparse
import BeautifulSoup
import sys
target = sys.argv[1]
a = urllib2.Request('http://torrents.ru/forum/search.php?nm='+urllib2.quote(target),
None,
{'Cookie': 'куки'})
b = urllib2.urlopen(a)
parser = BeautifulSoup.BeautifulSoup(b)
parsed = parser.findAll("p",attrs={'class':'small'})
if len(parsed) == 0:
print "Not found"
sys.exit()
parsed = parsed[0].fetch()
pages = []
if len(parsed) > 1:
parsed = parsed[3:-1]
for ent in parsed:
pages.append(ent.attrs[0][1])
titles = parser.findAll('a',attrs={'class':'topictitle'})
for title in titles:
print "".join(title.fetch(text=True)),
print urlparse.urljoin('http://torrents.ru/forum/',title.attrMap['href'])
for page in pages:
url = urlparse.urljoin("http://torrents.ru/forum/",page)
req = urllib2.Request(url,
None,
{'Cookie': 'куки'})
b = urllib2.urlopen(req)
parser = BeautifulSoup.BeautifulSoup(b)
parser.convertHTMLEntities=True
parser.convertEntities=True
titles = parser.findAll('a',attrs={'class':'topictitle'})
for title in titles:
title.convertEntities=True
parser.convertHTMLEntities=True
print u''.join(title.fetch(text=True)),
print urlparse.urljoin('http://torrents.ru/forum/',title.attrMap['href'])