import requests
import json
from urllib.parse import unquote_plus, urlencode
import execjs
# param中sec_user_id,msToken, a_bogus不同
# s_v_web_id和verifyFp和fp是一样的字符串
# ser_user_id是要爬取的用户id
def get_param(content):
items = content.split("&")
params = {}
for item in items:
key, value = item.split("=")
params[key] = unquote_plus(value)
print(params)
return params
def compare_dict(dict1, dict2):
for key,value in dict1.items():
value2 = dict2.get(key)
if value != value2:
print(key)
print(value)
print(value2)
def compare_str(st1, st2):
if st1 == st2:
print("yes")
def get_headers(content):
headers = {}
items = content.split("\n")
for i in range(0, len(items), 2):
key = items[i].strip()[:-1]
value = items[i+1].strip()
headers[key] = value
print(headers)
def get_ori_param(a_bogus, msToken):
print(unquote_plus(a_bogus))
print(unquote_plus(msToken))
def get_a_bogus(params):
with open("a_bogus.txt", "r", encoding="utf-8") as f:
code = f.read()
run = execjs.compile(code)
params = urlencode(params)
useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
result = run.call("get_result", params, useragent)
return result
def get_user_info(sec_user_id): # 获取用户信息
params = {
'device_platform': 'webapp',
'aid': '6383',
'channel': 'channel_pc_web',
'publish_video_strategy_type': '2',
'source': 'channel_pc_web',
'sec_user_id': sec_user_id,
'personal_center_strategy': '1',
'update_version_code': '170400',
'pc_client_type': '1',
'version_code': '170400',
'version_name': '17.4.0',
'cookie_enabled': 'true',
'screen_width': '1920',
'screen_height': '1080',
'browser_language': 'zh-CN',
'browser_platform': 'Win32',
'browser_name': 'Chrome',
'browser_version': '127.0.0.0',
'browser_online': 'true',
'engine_name': 'Blink',
'engine_version': '127.0.0.0',
'os_name': 'Windows',
'os_version': '10',
'cpu_core_num': '12',
'device_memory': '8',
'platform': 'PC',
'downlink': '10',
'effective_type': '4g',
'round_trip_time': '100',
'webid': '7352020997232952895',
'verifyFp': 'verify_lyiq18im_bzKnDO5f_8Xas_4fEz_9Ut5_yJwL7qSDjORm',
'fp': 'verify_lyiq18im_bzKnDO5f_8Xas_4fEz_9Ut5_yJwL7qSDjORm',
'msToken': 'VaJJmE7VogT3oxaKQkDbPxfmi2YFyUXZvhfxVkJJ7EzKV2JqMie1WtYQPYTspDq_YSxy6J56FZ2pwzputVjWqyJSDGC0GrumoX2KFNpvDCzkOm2pbO6lC7nfaOQicDY=',
}
a_bogus = get_a_bogus(params)
params["a_bogus"] = a_bogus
headers = {
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip',
'accept-language': 'zh-CN,zh;q=0.9',
'priority': 'u=1, i',
'referer': 'https://www.douyin.com/user/',
'sec-ch-ua': 'Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': 'Windows',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
}
cookies = {
"bd_ticket_guard_client_web_domain": "2",
"xgplayer_user_id": "767156888800",
"n_mh": "Mj-nEU9SMBRnNulYxyymVdBnMg-7fLF8bDs5UksbdSg",
"LOGIN_STATUS": "1",
"store-region": "cn-hn",
"store-region-src": "uid",
"ttwid": "1%7Cmcy4zyu3kma-WZgmXe0105EZszFRr5aTD8Zqs7DxRI0%7C1711775795%7C9ff653469f382fada1908c24ec677974467583a84dee9231200dfa95b424d4c2",
"SEARCH_RESULT_LIST_TYPE": "%22single%22",
"live_use_vvc": "%22false%22",
"passport_assist_user": "CkD85ZlQhSRATA3h6ThxWsfY8LzvMs2wUMw3Ntbx1obEHf9mneFSXJ2fyJMFIF0sscV5xBbbGYe8X85A03BPBlyoGkoKPHxwvpROddYxzwhPBjT7dQFvoMslRpuU7T0f7zpX2Uwbx_N6MI7BAel5d63LNj8XOjTklyxwHJ0Bo695fBDvktANGImv1lQgASIBAw025SY%3D",
"uid_tt": "0157df163cb278f99a1aa31485f9396e",
"uid_tt_ss": "0157df163cb278f99a1aa31485f9396e",
"sid_tt": "2b04f6f2dd55001187d775fd45f67519",
"sessionid": "2b04f6f2dd55001187d775fd45f67519",
"sessionid_ss": "2b04f6f2dd55001187d775fd45f67519",
"_bd_ticket_crypt_doamin": "2",
"_bd_ticket_crypt_cookie": "1e560ca7c63ce791fa120afe39e22b27",
"__security_server_data_status": "1",
"__live_version__": "%221.1.2.904%22",
"UIFID_TEMP": "29d6bea3e5a6c157a08a212e1912b5e8a78666ece26be56100fa19e58a63a45b650902132ba6b226b43d79d19a55e97ce04d654d29b04cbef0b1f178b3172039959536247e6934dd133b10e087f35a97",
"fpk2": "c92baae71318dc81de51a663df2f8b4f",
"UIFID": "29d6bea3e5a6c157a08a212e1912b5e8a78666ece26be56100fa19e58a63a45b48b2fe6eba42d23171b467a47d34dd105e973b52dc95b25532bf63070864815df4e92a33b57e92ebf46f1cdf6c0ebc4a98f2dff0594a4e91c65e93987a28567eb7d41df6398a0197cd697033979d3d43b8bcb5cc99f614d0f52cf447129458b5fb4da741a302fdb6bae720a430e10c1b3900af790b081cee1f1e5a8445a29b06",
"d_ticket": "653d63af13887feb7780cd6e7fca8f5b380b2",
"s_v_web_id": "verify_lyiq18im_bzKnDO5f_8Xas_4fEz_9Ut5_yJwL7qSDjORm",
"passport_csrf_token": "b65ea32fc66769c4cd580470935ee7a9",
"passport_csrf_token_default": "b65ea32fc66769c4cd580470935ee7a9",
"sid_guard": "2b04f6f2dd55001187d775fd45f67519%7C1721554757%7C5184000%7CThu%2C+19-Sep-2024+09%3A39%3A17+GMT",
"sid_ucp_v1": "1.0.0-KDBiZDgyZmU5YTE1ZGVhNzBhODczZWRjODI1NjU3OTI2NmNkZmM0ZWYKGwiYxPCS1fWKARDFrvO0BhjvMSAMOAZA9AdIBBoCaGwiIDJiMDRmNmYyZGQ1NTAwMTE4N2Q3NzVmZDQ1ZjY3NTE5",
"ssid_ucp_v1": "1.0.0-KDBiZDgyZmU5YTE1ZGVhNzBhODczZWRjODI1NjU3OTI2NmNkZmM0ZWYKGwiYxPCS1fWKARDFrvO0BhjvMSAMOAZA9AdIBBoCaGwiIDJiMDRmNmYyZGQ1NTAwMTE4N2Q3NzVmZDQ1ZjY3NTE5",
"dy_swidth": "1920",
"dy_sheight": "1080",
"publish_badge_show_info": "%220%2C0%2C0%2C1722828424215%22",
"my_rd": "2",
"download_guide": "%223%2F20240805%2F1%22",
"pwa2": "%220%7C0%7C3%7C1%22",
"WallpaperGuide": "%7B%22showTime%22%3A1722829509917%2C%22closeTime%22%3A0%2C%22showCount%22%3A1%2C%22cursor1%22%3A21%2C%22cursor2%22%3A0%2C%22hoverTime%22%3A1722831544406%7D",
"volume_info": "%7B%22isUserMute%22%3Atrue%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.693%7D",
"FOLLOW_RED_POINT_INFO": "%221%22",
"stream_player_status_params": "%22%7B%5C%22is_auto_play%5C%22%3A0%2C%5C%22is_full_screen%5C%22%3A0%2C%5C%22is_full_webscreen%5C%22%3A0%2C%5C%22is_mute%5C%22%3A1%2C%5C%22is_speed%5C%22%3A1%2C%5C%22is_visible%5C%22%3A1%7D%22",
"xg_device_score": "7.596210621920404",
"device_web_cpu_core": "12",
"device_web_memory_size": "8",
"architecture": "amd64",
"csrf_session_id": "61a1f6c03792771b145286f1d728e9eb",
"strategyABtestKey": "%221722910451.741%22",
"biz_trace_id": "94f3481e",
"FOLLOW_LIVE_POINT_INFO": "%22MS4wLjABAAAAaHkujDUjkMFvvL6pwDV2mHo59TuBgkFYhhlCNPVR0MI%2F1722960000000%2F1722910452766%2F1722910451044%2F0%22",
"passport_fe_beating_status": "true",
"__ac_nonce": "066b18f4d00232eb7915e",
"__ac_signature": "_02B4Z6wo00f01FwTFzwAAIDBgGqIiFFh36hcMxOAAHG8rW6MgyXgWTkQrDJuoTVteq3LwtFoLK1zx6D7XfkOOm4EV.FDfb9NX5y3U6cfNdHAgxprreSBfRBCsexE2Tadsa9a2rur21-jQ6g.c8",
"FOLLOW_NUMBER_YELLOW_POINT_INFO": "%22MS4wLjABAAAAaHkujDUjkMFvvL6pwDV2mHo59TuBgkFYhhlCNPVR0MI%2F1722960000000%2F0%2F0%2F1722914021882%22",
"stream_recommend_feed_params": "%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1920%2C%5C%22screen_height%5C%22%3A1080%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A12%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22",
"bd_ticket_guard_client_data": "eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCR3FWOWhVZ01xWWcrK0lLRUszT2NVVnVmM3NJYmxtVVZQQ0ZzZmUyWVJPVWgvWTlSY3ZNQ0JXYjRmY2tlaHdCRzI5R3NGcXdWWDA3T0JFSXNRUzZzVGs9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D",
"IsDouyinActive": "true",
"home_can_add_dy_2_desktop": "%220%22",
"odin_tt": "9c0d7e476016443d2a99d06c53b726820e77a86e5f2eaed6fd4aee9b2a9efbf0035e7e629a7cf4c0fd0056530919cf3d"
}
url = "https://www.douyin.com/aweme/v1/web/user/profile/other/"
req = requests.get(url, params=params, headers=headers, cookies=cookies)
print(req.text)
if __name__ == '__main__':
user_id = "MS4wLjABAAAAH0Muz9yuNuxbK94G2D0qnBbG68a4sUszfiji49ym19TjR8bhXwpAqORdzmW2fr6G"
get_user_info(user_id)
cookie应该是不用变的,只需要逆向a_bogus参数,msToken好像也可以用很久,至少现在还能用,感觉可以随机,a_bogus.txt代码GitHub - KTVICTORY18/js-: 这里是我的js逆向代码中的a_bogus.txt,暂时还是可以用的。祝大家爬的开心