Open Openover-zh opened 1 year ago
# !/usr/bin/env python # -*- encoding: utf-8 -*-
import requests, random, urllib.parse
def get_ttwid(): """ ttwid生成 """ data = {"region": "cn", "aid": 6383, "needFid": False, "service": "www.ixigua.com", "migrate_info": {"ticket": "", "source": "node"}, "cbUrlProtocol": "https", "union": True} headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36', } url = "https://ttwid.bytedance.com/ttwid/union/register/" res = requests.post(url, json=data)
cookie = res.headers['Set-Cookie'] # print(cookie) ttwid = cookie.split(' ')[0] # print(ttwid) # 去掉ttwid=,ttwid后面的分号 ttwid = ttwid.replace("ttwid=", "").replace(";", "") return ttwid
def generate_random_str(randomlength=107): """ 根据传入长度产生随机字符串 :param randomlength: 随机字符串长度 """ random_str = '' base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789=' length = len(basestr) - 1 for in range(randomlength): random_str += base_str[random.randint(0, length)]
return random_str
def get_x_bogus(url): """ X-Bogus生成 param url: 参数中的url """ data = { "url": url, "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", "Referer": "https://www.douyin.com/" }
postUrl = "https://tiktok.iculture.cc/X-Bogus" res = requests.post(postUrl, json=data) return res.json()
def main(): odin_tt = "96c6362a1ac61572d7b175aa3671e30c521cefdce0b0d620c2b4c0170cf86217" ttwid = get_ttwid() msToken = generate_random_str() bd_ticket_guard_client_data = "eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWNsaWVudC1jc3IiOiItLS0tLUJFR0lOIENFUlRJRklDQVRFIFJFUVVFU1QtLS0tLVxyXG5NSUlCRFRDQnRRSUJBREFuTVFzd0NRWURWUVFHRXdKRFRqRVlNQllHQTFVRUF3d1BZbVJmZEdsamEyVjBYMmQxXHJcbllYSmtNRmt3RXdZSEtvWkl6ajBDQVFZSUtvWkl6ajBEQVFjRFFnQUVKUDZzbjNLRlFBNUROSEcyK2F4bXAwNG5cclxud1hBSTZDU1IyZW1sVUE5QTZ4aGQzbVlPUlI4NVRLZ2tXd1FJSmp3Nyszdnc0Z2NNRG5iOTRoS3MvSjFJc3FBc1xyXG5NQ29HQ1NxR1NJYjNEUUVKRGpFZE1Cc3dHUVlEVlIwUkJCSXdFSUlPZDNkM0xtUnZkWGxwYmk1amIyMHdDZ1lJXHJcbktvWkl6ajBFQXdJRFJ3QXdSQUlnVmJkWTI0c0RYS0c0S2h3WlBmOHpxVDRBU0ROamNUb2FFRi9MQnd2QS8xSUNcclxuSURiVmZCUk1PQVB5cWJkcytld1QwSDZqdDg1czZZTVNVZEo5Z2dmOWlmeTBcclxuLS0tLS1FTkQgQ0VSVElGSUNBVEUgUkVRVUVTVC0tLS0tXHJcbiJ9"
url = "https://www.douyin.com/aweme/v1/web/general/search/single/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_general&sort_type=0&publish_time=0&keyword=%E5%8E%84%E6%96%90%E7%90%89%E6%96%AF%E5%8D%A1%E4%B8%89%E5%88%80&search_source=normal_search&query_correct_type=1&is_filter_search=0&from_group_id=&offset=0&count=15&pc_client_type=1&version_code=190600&version_name=19.6.0&cookie_enabled=true&screen_width=1920&screen_height=1080&browser_language=zh-CN&browser_platform=MacIntel&browser_name=Chrome&browser_version=114.0.0.0&browser_online=true&engine_name=Blink&engine_version=114.0.0.0&os_name=Mac+OS&os_version=10.15.7&cpu_core_num=8&device_memory=8&platform=PC&downlink=5.2&effective_type=4g&round_trip_time=250&webid=7234455109030135296" # msToken url = url + "&msToken=" + msToken res = get_x_bogus(url) url = res['param'] xBogus = res['X-Bogus'] # #url 后面加msToken print(url, xBogus) headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", "Referer": "https://www.douyin.com/", "Cookie": f"msToken={msToken};ttwid={ttwid};passport_csrf_token=042487bb53a6be39288681442c9c0b79;passport_csrf_token_default=042487bb53a6be39288681442c9c0b79;__ac_signature=_02B4Z6wo00f01ZpabpgAAIDCyi0qYxUwfMmaemoAAAIYCjfqrLBvvH16dJEuiZQKPIdp5.5-KxRfRrjwKYL2Se5aXopbua1p.HbiUIDe2FJ2Mbak5qlu7LvLMDKv-6LUft.fufdUee5WXjjga1;LOGIN_STATUS=0;odin_tt={odin_tt};tt_scid=e6mq8ADwPUb-Z2GLj7dtviRhibMq0MbncrDgoqLgJJ-q84TK2c9.dxtNni9hlAHcb610;sid_tt=12e1d5a11ade9a71600d7d2ef8e67edc", } # print(headers) # #请求抖音接口 res = requests.get(url, headers=headers) print("结果", res.text)
if name == 'main': main()
你的odin_tt 哪来的?字符长度明显不对...
import requests, random, urllib.parse
def get_ttwid(): """ ttwid生成 """ data = {"region": "cn", "aid": 6383, "needFid": False, "service": "www.ixigua.com", "migrate_info": {"ticket": "", "source": "node"}, "cbUrlProtocol": "https", "union": True} headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36', } url = "https://ttwid.bytedance.com/ttwid/union/register/" res = requests.post(url, json=data)
获取headers中的ttwid
def generate_random_str(randomlength=107): """ 根据传入长度产生随机字符串 :param randomlength: 随机字符串长度 """ random_str = '' base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789=' length = len(basestr) - 1 for in range(randomlength): random_str += base_str[random.randint(0, length)]
def get_x_bogus(url): """ X-Bogus生成 param url: 参数中的url """ data = { "url": url, "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36", "Referer": "https://www.douyin.com/" }
postUrl = "http://127.0.0.1:8787/X-Bogus"
def main(): odin_tt = "96c6362a1ac61572d7b175aa3671e30c521cefdce0b0d620c2b4c0170cf86217" ttwid = get_ttwid() msToken = generate_random_str() bd_ticket_guard_client_data = "eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWNsaWVudC1jc3IiOiItLS0tLUJFR0lOIENFUlRJRklDQVRFIFJFUVVFU1QtLS0tLVxyXG5NSUlCRFRDQnRRSUJBREFuTVFzd0NRWURWUVFHRXdKRFRqRVlNQllHQTFVRUF3d1BZbVJmZEdsamEyVjBYMmQxXHJcbllYSmtNRmt3RXdZSEtvWkl6ajBDQVFZSUtvWkl6ajBEQVFjRFFnQUVKUDZzbjNLRlFBNUROSEcyK2F4bXAwNG5cclxud1hBSTZDU1IyZW1sVUE5QTZ4aGQzbVlPUlI4NVRLZ2tXd1FJSmp3Nyszdnc0Z2NNRG5iOTRoS3MvSjFJc3FBc1xyXG5NQ29HQ1NxR1NJYjNEUUVKRGpFZE1Cc3dHUVlEVlIwUkJCSXdFSUlPZDNkM0xtUnZkWGxwYmk1amIyMHdDZ1lJXHJcbktvWkl6ajBFQXdJRFJ3QXdSQUlnVmJkWTI0c0RYS0c0S2h3WlBmOHpxVDRBU0ROamNUb2FFRi9MQnd2QS8xSUNcclxuSURiVmZCUk1PQVB5cWJkcytld1QwSDZqdDg1czZZTVNVZEo5Z2dmOWlmeTBcclxuLS0tLS1FTkQgQ0VSVElGSUNBVEUgUkVRVUVTVC0tLS0tXHJcbiJ9"
if name == 'main': main()