
weibo 游客 SUB 附python源码
python获取微博游客cookie sub
·
直入正文,目前微博接口cookie增加了cookie的验证,简单测试只有SUB是必须的。
以下是web端.com,SUB的生成
先用浏览器的访客或者无痕模式,目的是为了使用一个纯净的初始环境,不然会有很多东西会干扰我们接下来的分析。
复制这个值,再抓包软件中搜索一下,我这里使用的reqable为例,工具不重要。
# -*- coding: utf-8 -*-
import re
import json
import requests
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
}
def create_sub():
data = {
'cb': 'visitor_gray_callback',
'tid': '',
'from': 'weibo',
}
response = requests.post('https://passport.weibo.com/visitor/genvisitor2', headers=headers, data=data)
sub = json.loads(re.findall(r'({.*})', response.text)[0])['data']['sub']
print(f"生成新的sub : {sub}")
return sub
url = "https://weibo.com/ajax/statuses/show"
cookies = {"SUB": create_sub()}
params = {
"id": 'P1it6omnI'
}
# http://weibo.com/1651529385/P1it6omnI
response = requests.get(url, headers=headers, params=params, cookies=cookies).text
print(response)
更多推荐
所有评论(0)