Skip to content

Instantly share code, notes, and snippets.

@est
Last active December 21, 2015 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save est/6505af70c18ca25a46fc to your computer and use it in GitHub Desktop.
Save est/6505af70c18ca25a46fc to your computer and use it in GitHub Desktop.
hide weibo
#!/usr/bin/env python
# coding: utf8
# this script to hide previous weibo
# MIT license
import re, time, random
import requests
owner_uid = 0 # your uid
guest_cookie = '' # SUB value
owner_cookie = '' # SUB value
visible_level = 2 # 1: self-only, 2: friend circle
start_page = 3
def mute_one(mid):
r = requests.post(
'http://weibo.com/p/aj/v6/mblog/modifyvisible?ajwvr=6&domain=100505&__rnd=1450331041601',
data={
'visible': visible_level,
'mid': mid,
'_t': '0',
},
cookies={
'SUB': owner_cookie
},
headers={
'Referer': 'http://weibo.com/%s/profile' % owner_uid
}
)
r.encoding = None
j = r.json()
print mid, j['code'], j['msg'][:60]
def set_many(rsp):
rsp.encoding = None
print rsp.url
try:
data = rsp.json().get('data').strip()
except ValueError:
data = rsp.text.strip()
if not data:
return
for mid in re.findall(r'<a name=(\d+)', data):
time.sleep(random.random()*3)
mute_one(mid)
return (data
if len(data) < 60 else
'%s... %s' % (data[:60], len(data))
).replace('\r', '').replace('\n', '')
def get_web():
p = start_page
while True:
# first pass
time.sleep(random.random()*5)
r = requests.get('http://weibo.com/p/aj/v6/mblog/mbloglist', params={
'domain': 100505,
'is_all': 1,
'page': p,
'id': '100505%s' % owner_uid,
}, cookies={
'SUB': guest_cookie
})
print p, set_many(r)
time.sleep(random.random()*5)
r = requests.get('http://weibo.com/p/aj/v6/mblog/mbloglist', params={
'domain': 100505,
'is_all': 1,
'page': p,
'pre_page': p,
'id': '100505%s' % owner_uid,
}, cookies={
'SUB': guest_cookie
})
print p, set_many(r)
time.sleep(random.random()*5)
r = requests.get('http://weibo.com/p/aj/v6/mblog/mbloglist', params={
'domain': 100505,
'is_all': 1,
'page': p,
'pre_page': p,
'pagebar': 1,
'id': '100505%s' % owner_uid,
}, cookies={
'SUB': guest_cookie
})
print p, set_many(r)
p += 1
if '__main__' == __name__:
get_web()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment