usr bin env python -coding utf-8- import re import mechanize from Beau

 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
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
#-*-coding:utf-8-*-
import re
import mechanize
from BeautifulSoup import BeautifulSoup
def prettify_response(br):
r = br.response()
s = r.get_data()
soup = BeautifulSoup(s)
s = soup.prettify()
r.set_data(s)
br.set_response(r)
return s
br = mechanize.Browser()
br.open('http://mamba.ru/tips/?tip=Login')
br.select_form("login")
br["login"] = 'pasword2000'
br["password"] = 'marahabi'
br.submit()
l = br.find_link(text=u'Знакомства')
br.follow_link(link=l)
prettify_response(br)
br.select_form('msearch')
br['s_i'] = 'F'
br['s_l'] = 'N'
br['s_f'] = '20'
br['s_t'] = '20'
br['s_c'] = ['3159_5246_5269']
#br['s_p'] = []
#br['s_v'] = []
#br['s_vip'] = []
#br['s_w'] = []
br.submit()
s = prettify_response(br)
soup = BeautifulSoup(s)
s = soup.prettify()
re1 = re.compile('(?isu)<a href=".+?anketaId=(\d+).+?">(.+?)</a>\s*,\s*(\d+)\s*</b>\s*<img src=".+?ico_(.+?)\.gif".+?/>\s*<span class="search-town">(.+?)</span>')
rows = soup.findAll('div',id='SearchPage')[0].findAll('li')
i = 0
for row in rows:
res = re1.search(str(row.table.findAll('div',{'class':'search-user-info'})[0]))
i += 1
print i
print res.groups()