This repository was archived by the owner on Feb 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclean_sina_weibo_httplib.py
More file actions
159 lines (145 loc) · 5.08 KB
/
Copy pathclean_sina_weibo_httplib.py
File metadata and controls
159 lines (145 loc) · 5.08 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#coding: utf8
import re
import time
from urlparse import parse_qsl, urljoin
from urlfetch import *
URL_LOGIN = 'http://3g.sina.com.cn/prog/wapsite/sso/login_submit.php'
TIME_SLEEP = 1 # sec
class Sina(object):
def __init__(self, username, password):
self.cookies = None
self.username = username
self.password = password
def login(self):
response = fetch(URL_LOGIN)
data = response.body
vk = re.search(r'''name="vk"\s+?value="(.*?)"''', data).group(1)
pname = re.search(r'''name="password_(\d+)"''', data).group(1)
post = {
'mobile': self.username,
'password_'+pname: self.password,
#'capId': capid,
'vk': vk,
'remember': 'on',
'submit': '1'
}
response = fetch(URL_LOGIN, data=post)
data = response.body
captcha = re.search(r'''captcha/show.php\?cpt=(\w+)''', data)
if captcha:
url = '''http://weibo.cn/interface/f/ttt/captcha/show.php?cpt=''' + captcha.group(1)
print url
captcha = raw_input("open the url and input the captcha:")
vk = re.search(r'''name="vk"\s+?value="(.*?)"''', data).group(1)
pname = re.search(r'''name="password_(\d+)"''', data).group(1)
capid = re.search(r'''name="capId"\s+?value="(.*?)"''', data).group(1)
post = {
'mobile': self.username,
'password_'+pname: self.password,
'capId': capid,
'vk': vk,
'remember': 'on',
'submit': '1',
'code': captcha.strip(),
}
response = fetch(URL_LOGIN, data=post)
self.cookies = response.cookiestring
print self.cookies
response = fetch(
'http://weibo.cn/',
headers = {'Cookie': self.cookies, 'User-Agent': 'Android'},
)
self.uid = re.search(r'''uid=(\d+)''', response.body).group(1)
print self.uid
return self.cookies
def del_tweets(self):
while True:
time.sleep(2 * TIME_SLEEP)
response = fetch(
'http://weibo.cn/%s/profile' % self.uid,
headers={'Cookie': self.cookies}
)
data = re.findall(r'href="http://weibo.cn/mblog/del\?(.*?)"', response.body)
if not data:
break
for i in data:
time.sleep(TIME_SLEEP)
j = parse_qsl(i)
qs = dict(j)
qs['act'] = 'delc'
qs = '&'.join(['='.join(k) for k in qs.items()])
url = 'http://weibo.cn/mblog/del?' + qs
try:
fetch(
url,
headers = {'Cookie': self.cookies}
)
print url
except:pass
def unfollow(self):
while True:
time.sleep(2 * TIME_SLEEP)
response = fetch(
'http://weibo.cn/%s/follow' % self.uid,
headers={'Cookie': self.cookies}
)
data = re.findall(r'href="/attention/del\?(.*?)"', response.body)
if not data:
break
for i in data:
time.sleep(TIME_SLEEP)
j = parse_qsl(i)
qs = dict(j)
qs['act'] = 'delc'
qs = '&'.join(['='.join(k) for k in qs.items()])
url = 'http://weibo.cn/attention/del?' + qs
try:
fetch(
url,
headers = {'Cookie': self.cookies}
)
print url
except:pass
def remove_followers(self, black=False):
while True:
time.sleep(2 * TIME_SLEEP)
response = fetch(
'http://weibo.cn/%s/fans' % self.uid,
headers={'Cookie': self.cookies}
)
data = re.findall(r'href="/attention/remove\?(.*?)"', response.body)
if not data:
break
for i in data:
time.sleep(TIME_SLEEP)
j = parse_qsl(i)
qs = dict(j)
qs['act'] = 'removec'
if black:
qs['black'] = 1
qs = '&'.join(['='.join(k) for k in qs.items()])
url = 'http://weibo.cn/attention/remove?' + qs
try:
fetch(
url,
headers = {'Cookie': self.cookies}
)
print url
except:pass
if __name__ == '__main__':
def sigint():
def _sigint(a,b):
print a, b
import os, sys
os.kill(0, signal.SIGTERM)
sys.exit()
import signal
signal.signal(signal.SIGINT, _sigint)
import sys
sigint()
username, password = sys.argv[1:]
sina = Sina(username, password)
sina.login()
sina.del_tweets()
#sina.unfollow()
#sina.remove_followers()