Created
December 5, 2017 04:24
-
-
Save zxc111/f941acc31d3d77e9380900c02c99f317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
import urllib2 | |
import json | |
import urllib | |
url = "https://passport.weibo.com/visitor/genvisitor" | |
headers = """Connection: keep-alive | |
Cache-Control: max-age=0 | |
Origin: https://passport.weibo.com | |
If-Modified-Since: 0 | |
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 | |
Content-Type: application/x-www-form-urlencoded | |
Accept: */* | |
DNT: 1 | |
Referer: https://passport.weibo.com/visitor/visitor?entry=miniblog&a=enter&url=https%3A%2F%2Fweibo.com%2F&domain=.weibo.com&ua=php-sso_sdk_client-0.6.23&_rand=1512370562.2262 | |
Accept-Encoding: gzip, deflate, br | |
Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7""" | |
headers = dict(map(lambda x: x.split(": "), headers.split("\n"))) | |
data = "cb=gen_callback&fp=%7B%22os%22%3A%223%22%2C%22browser%22%3A%22Chrome62%2C0%2C3202%2C94%22%2C%22fonts%22%3A%22undefined%22%2C%22screenInfo%22%3A%221920*1080*24%22%2C%22plugins%22%3A%22Portable%20Document%20Format%3A%3Ainternal-pdf-viewer%3A%3AChrome%20PDF%20Plugin%7C%3A%3Amhjfbmdgcfjbbpaeojofohoegiehjai%3A%3AChrome%20PDF%20Viewer%7C%3A%3Ainternal-nacl-plugin%3A%3ANative%20Client%7CEnables%20Widevine%20licenses%20for%20playback%20of%20HTML%20audio%2Fvideo%20content.%20(version%3A%201.4.8.1029)%3A%3Alibwidevinecdmadapter.so%3A%3AWidevine%20Content%20Decryption%20Module%22%7D" | |
req = urllib2.Request(url,) | |
req.headers = headers | |
body = urllib2.urlopen(req, data=data).read() | |
info = json.loads(body[36: -2])["data"] | |
tid = info["tid"] | |
confidence = info["confidence"] | |
where = 3 if info["new_tid"] else 2 | |
new_url = "https://passport.weibo.com/visitor/visitor?a=incarnate&t={}&w={}&c={}&gc=&cb=cross_domain&from=weibo&_rand=0.25684571263310".format(urllib.quote(tid), where, confidence) | |
req = urllib2.Request(new_url) | |
req.headers = headers | |
body = urllib2.urlopen(req).read() | |
body = json.loads(body[36: -2])["data"] | |
sub = body["sub"] | |
subp = body["subp"] | |
req = urllib2.Request("https://weibo.com") | |
headers["Cookie"] = "SUB=%s; SUBP=%s" % (sub, subp) | |
req.headers = headers | |
print response = urllib2.urlopen(req).read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment