6 #from .. import spamavert.com
8 def get_src( url
, post
= None, headers
=None, noredirect
=False):
10 class NoRedirect( urllib2
.HTTPRedirectHandler
):
11 def http_error_302(self
, req
, fp
, code
, msg
, headers
):
14 httplib
.HTTPConnection
.debuglevel
= 0
15 request
= urllib2
.Request(url
, post
, unverifiable
=True)
16 request
.add_header('Accept-encoding', 'gzip')
17 request
.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8')
19 for key
, val
in headers
.items():
20 request
.add_header(key
, val
)
21 opener
= urllib2
.build_opener(NoRedirect
)
23 f
= opener
.open(request
)
24 except urllib2
.HTTPError
, e
:
26 mode
= f
.headers
.get('Content-Encoding')
31 from StringIO
import StringIO
32 compressstream
= StringIO( src
)
34 src
= gzip
.GzipFile(fileobj
= compressstream
).read()
38 return type('Response',(),{'headers' :f
.headers
.dict, 'src': src
})
43 self
.site
= 'http://torrents.ru/forum/'
47 def auth(self
, login
, password
):
48 stage_1
= get_src(self
.site
+'login.php')
49 temp_cookie
= stage_1
.headers
.get('set-cookie')
51 'redirect':'index.php',
52 'cookie_test':temp_cookie
.split('=')[1],
53 'login_username':login
,
54 'login_password':password
,
58 stage_2
= get_src('http://torrents.ru/forum/login.php', send_auth_form
, {'Cookie':temp_cookie
})
59 self
.cookie
= stage_2
.headers
.get('set-cookie')
63 def soup_load(self
, src
, fromEncoding
='CP1251'):
64 src2
= re
.sub('<script(|.*?)>[\S\s]*?</script>','',src
)
65 return BeautifulSoup
.BeautifulStoneSoup(src2
, fromEncoding
=fromEncoding
)
67 def find_torrents(self
, word
=''):
86 src
= get_src(self
.site
+'tracker.php', search_form
, {'Cookie':self
.cookie
})
88 soup
= self
.soup_load( src
.src
)
90 for t
in soup
.findAll('tr', {'class':"tCenter"}):
91 theme_link
= t
.find('a', {'class':"genmed tLink"})
92 torrent_link
= t
.find('a' ,{'class':"small tr-dl dl-stub"})
93 if theme_link
and torrent_link
:
94 list_topic
.append( (self
.site
+theme_link
.get('href')[2:], self
.site
+torrent_link
.get('href')) )
97 def get_torrents_info_from_page(self
, url
):
98 'seeds (Nick, profile), leech, url_torrent_file,'
99 src
= get_src( url
+'&spmode=full',headers
={'Cookie': self
.cookie
} )
100 soup
= self
.soup_load( src
.src
)
101 for s
in soup
.findAll('a',{'class':'seedmed'} ):
102 name
= s
.find(text
=True)
103 profile
= s
.get('href')
104 print name
,self
.site
+profile
106 for s
in soup
.findAll('a',{'class':'leechmed'} ):
107 name
= s
.find(text
=True)
108 profile
= s
.get('href')
109 print name
,self
.site
+profile
113 def load_torrent(self
, url
=''):
123 def __load_torrent(self
):
126 def auth(self
, user
, password
):
131 from tempfile
import _RandomNameSequence
as RandName
133 def reg(usersyffix
='nyaka_2009_1',password
='qazqaz'):
134 email
= RandName().next()+'@spamavert.com'
136 request
= urllib2
.Request('http://torrents.ru/forum/profile.php?mode=register', {'reg_agreed':'1'})
137 #request.add_header('Accept-encoding', 'gzip')
138 request
.add_header('Cookie','spylog_test=1')
139 request
.add_header('Referer','http://torrents.ru/forum/profile.php?mode=register')
140 opener
= urllib2
.build_opener()
141 f
= opener
.open(request
)
145 captcha_id
= re
.findall('<input type="hidden" name="confirm_id" value="(.*?)" />', src
)[0]
150 'confirm_id': captcha_id
,
151 'username': 'nyaka_1004',
153 'new_password': password
,
154 'password_confirm': password
,
155 'cfmcd' : 'yg1q', #captcha
156 'user_flag_id': '195',
157 'user_timezone_x2': '6',
159 captcha_img
= 'http://torrents.ru/forum/profile.php?mode=confirm&id='+captcha_id
162 if __name__
== '__main__':
164 #bot.auth('nyaka_1002','qazqaz')
168 a
= os
.popen('python captcha.py http://www.google.ru/images/nav_logo4.png').read()
170 #bot.get_torrents_info_from_page('http://torrents.ru/forum/viewtopic.php?t=200486')