This repository was archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser.py
66 lines (63 loc) · 2.21 KB
/
user.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# coding: utf-8
import mechanize
import re
import requests
import Image
from StringIO import StringIO
def get_album_list(sid, frienduid):
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20100101 Firefox/10.0.12 Iceweasel/10.0.12')]
br.open("http://3g.renren.com/album/wmyalbum.do?id=%s&sid=%s" % (
str(frienduid), str(sid)
))
outlinks = {}
while True:
links = br.links(url_regex=r"wgetalbum.do")
for i in links:
outlinks[i.url] = i.text
lenf = 0
for i in br.forms():
lenf += 1
for i in xrange(lenf):
k = 0
for j in br.forms():
br.form = j
k += 1
if k > i:
break
br['password'] = raw_input(u'发现一个加密相册,请输入密码:')
br.submit()
outlinks[br.geturl()] = br.title()
br.back()
retry = 1
while retry:
retry = 0
try:
br.follow_link(text_regex=r"下一页", url_regex="wmyalbum.do")
except mechanize._mechanize.LinkNotFoundError:
return outlinks
except Exception as e:
retry = 1
def get_sid(username, password):
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders = [('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20100101 Firefox/10.0.12 Iceweasel/10.0.12')]
resp = br.open("http://3g.renren.com/")
for i in br.forms():
br.form = i
break
html = resp.read()
url = re.search(r'\/rndimg_wap[^"]*"', html).group(0)[:-1]
checkcode = requests.get("http://3g.renren.com" + url).content
img = Image.open(StringIO(checkcode))
img.show()
br['email'] = username
br['password'] = password
br['verifycode'] = raw_input(u'请输入验证码:')
res = br.submit()
if 'sid' in res.geturl():
return (True, re.search('sid=([^?&]*)', res.geturl()).group(1))
else:
return (False, re.search(r'<div class="error">(.*?)</div>', res.read()).group(1).decode('utf-8'))