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" def try_flow(referer, service, aid, next_url=None): headers = { "User-Agent": UA, "Referer": referer, "Accept": "application/json, text/plain, */*", "Origin": referer.rstrip("/"), } s = requests.Session() 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=headers, timeout=15, ) s.get(referer, headers=headers, timeout=15) ts = int(time.time() * 1000) params = {"aid": str(aid), "service": service, "is_vcd": "1", "t": ts} if next_url: params["next"] = next_url r = s.get("https://sso.douyin.com/get_qrcode/", params=params, headers=headers, timeout=15) print("===", referer, aid, r.status_code, r.headers.get("content-type")) if "json" in (r.headers.get("content-type") or ""): print(r.text[:500]) else: print(r.text[:100]) for ref, svc, aid, nxt in [ ("https://creator.douyin.com/", "https://creator.douyin.com", 2906, "https://creator.douyin.com"), ("https://www.douyin.com/", "https://www.douyin.com", 6383, None), ("https://www.douyin.com/", "https://www.douyin.com", 1128, "https://www.douyin.com"), ]: try_flow(ref, svc, aid, nxt)