本文所有教程及源码、软件仅为技术研究。不涉及计算机信息系统功能的删除、修改、增加、干扰,更不会影响计算机信息系统的正常运行。不得将代码用于非法用途,如侵立删! |
头条搜索精选 参数分析
环境
- win10
- Python3.9
- Chrome
抓包接口分析
主要是需要这一块的内容
通过抓包分析发现在html中直接有json数据
现在只需要请求页面然后提取出需要的json数据即可,现在重点分析一下请求所需的参数,经过测试得知,ttwid是必要参数,看长度和验证流程和dy极为相似,直接用dy的套一下测试发现是一样的。
cookies = {
# "tt_webid": "7221851119085061689",
# "_ga": "GA1.1.1371017124.1681468304",
# "passport_csrf_token": "086bf595bf03413a64b6250e818f8861",
# "_ga_QEHZPBE5HH": "GS1.1.1687776009.2.0.1687776009.0.0.0",
"ttwid": "1%7C22KnJ4OamTx5lIoxDKM-JBA_0MZigRB0iOvI-ouOU%7C1687776011%7C5a059c3a4eaa05094b2389065993850c62df3b6095a3b5b9abb6ebbbd781d4",
# "_tea_utm_cache_4916": "undefined",
# "_S_WIN_WH": "1366_657",
# "_S_DPR": "1",
# "_S_IPAD": "0",
"s_v_web_id": "verify_ljcqae1y_flG7UGHi_j6mx_4ZjM_8dt3_z9Lxvp74pqk5"
}
ttwid生成
验证流程:
1.先获取__ac_nonce
2.根据__ac_nonce本地生成__ac_signature
3.使用__ac_nonce和__ac_signature 获取ttwid
headers_base = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
"sec-ch-ua": "\"Chromium\";v=\"104\", \" Not A;Brand\";v=\"99\", \"Google Chrome\";v=\"104\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\""
}
url = f"https://www.toutiao.com/"
# sess.mount(url , CipherAdapter())
__ac_nonce = sess.get(url, headers=headers_base).cookies.get('__ac_nonce')
print(__ac_nonce)
__ac_signature = get_ac_sign(__ac_nonce)
print(__ac_signature)
headers = {
'cookie': f'__ac_nonce={__ac_nonce}; __ac_signature={__ac_signature};
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36'
}
ttwid = requests.get(headers=headers).cookies.get('ttwid')
print(ttwid)
效果
资源下载
https://download.csdn.net/download/qq_38154948/87951323
本文仅供学习交流使用,如侵立删! |
标签:__,nonce,ac,ttwid,headers,参数,signature,搜索,头条 From: https://www.cnblogs.com/c1033383881/p/17506665.html