重构为 HTTP SSO 扫码方案并引入 Vue3 前端
移除 Playwright 浏览器自动化,改用 passport/SSO HTTP 接口获取二维码与轮询登录;后端模块化拆分,前端替换为 Vue3 SPA。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import requests
|
||||
import time
|
||||
|
||||
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
|
||||
|
||||
s = requests.Session()
|
||||
base_headers = {
|
||||
"User-Agent": UA,
|
||||
"Referer": "https://www.douyin.com/",
|
||||
"Accept": "application/json, text/plain, */*",
|
||||
"Origin": "https://www.douyin.com",
|
||||
}
|
||||
|
||||
s.post(
|
||||
"https://ttwid.bytedance.com/ttwid/union/register/",
|
||||
json={
|
||||
"region": "cn",
|
||||
"aid": 1768,
|
||||
"needFid": False,
|
||||
"service": "www.douyin.com",
|
||||
"migrate_info": {"ticket": "", "source": "web"},
|
||||
"cbUrlProtocol": "https",
|
||||
"union": True,
|
||||
},
|
||||
headers=base_headers,
|
||||
timeout=15,
|
||||
)
|
||||
s.get("https://www.douyin.com/", headers=base_headers, timeout=15)
|
||||
s.get("https://www.douyin.com/passport/web/login/", headers=base_headers, timeout=15)
|
||||
|
||||
csrf = None
|
||||
for c in s.cookies:
|
||||
if c.name == "passport_csrf_token":
|
||||
csrf = c.value
|
||||
break
|
||||
print("passport_csrf_token", csrf)
|
||||
print("all cookies", [(c.name, c.domain) for c in s.cookies])
|
||||
|
||||
ts = int(time.time() * 1000)
|
||||
params = {
|
||||
"aid": "6383",
|
||||
"service": "https://www.douyin.com",
|
||||
"need_logo": "false",
|
||||
"is_vcd": "1",
|
||||
"t": str(ts),
|
||||
}
|
||||
headers = dict(base_headers)
|
||||
if csrf:
|
||||
headers["x-tt-passport-csrf-token"] = csrf
|
||||
|
||||
for method in ("GET", "POST"):
|
||||
if method == "POST":
|
||||
r = s.post(
|
||||
"https://www.douyin.com/passport/web/get_qrcode/",
|
||||
params=params,
|
||||
headers=headers,
|
||||
timeout=15,
|
||||
)
|
||||
else:
|
||||
r = s.get(
|
||||
"https://www.douyin.com/passport/web/get_qrcode/",
|
||||
params=params,
|
||||
headers=headers,
|
||||
timeout=15,
|
||||
)
|
||||
print(method, r.status_code, r.text[:500])
|
||||
Reference in New Issue
Block a user