第一次尝试
import requests
url = 'https://web.umeng.com/main.php?c=site&a=show'
res = requests.get(url)
with open('cnzz.html', 'w', encoding='utf-8') as file_obj:
file_obj.write(res.text)
'''
CNZZ.html
<script>location.href='main.php?c=user&a=tip&code=1000¶m3=aHR0cHM6Ly93ZWIudW1lbmcuY29tL21haW4ucGhwP2M9c2l0ZSZhPXNob3c=&channel='+escape(window.location.hash);</script>
''''
思路总结第一次没有引入 cookie以及user-agent
完后代码
import requests
url = 'https://web.umeng.com/main.php?c=site&a=show'
header = {
'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',
'cookie':'UM_distinctid=179cb4e18f51f8-0f8d21d489e11-1f386252-232800-179cb4e18f6411; dplus_cross_id=179cb4e18fc495-0a1a79c9922591-1f386252-232800-179cb4e18fd5dd; dplus_finger_print=189247390; Hm_lvt_289016bc8d714b0144dc729f1f2ddc0d=1622613565; cna=KAw+GQBhi2oCAXc5rxvGeRe7; uc_session_id=0b8b5ecc-26e1-4c4d-b9a1-b606320c9a7f; xlly_s=1; umplus_uc_token=1eHukJCqxzn_Bk2gXQEJiVA_05182ff637c444858219b16d450d13ef; umplus_uc_loginid=3394321186%40qq.com; Hm_lpvt_289016bc8d714b0144dc729f1f2ddc0d=1622613682; cn_1258498910_dplus=1%5B%7B%7D%2C0%2C1622613681%2C0%2C1622613681%2C%22www.baidu.com%22%2C%22179cb4e18f51f8-0f8d21d489e11-1f386252-232800-179cb4e18f6411%22%2C%221622609943%22%2C%22https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DmxOAYJ5NRHF_JNEhmvg-Z7E7kj5YsfF3xfsVB1rnJ23%26wd%3D%26eqid%3Dca99edcc00056f910000000360b71e21%22%2C%22www.baidu.com%22%5D; isg=BOLiXbZd9orWFOrWQtX-zmcdM25EM-ZN-RNuSix7CtUA_4J5FMC2XGd9KzsDb17l; edtoken=cnzz_60b71ea3b2802; PHPSESSID=9sea3v8ia9tbig58dv8noa3j47; CNZZDATA33222=cnzz_eid%3D722568395-1622609538-https%253A%252F%252Fworkbench.umeng.com%252F%26ntime%3D1622609538; cn_1259864772_dplus=1%5B%7B%7D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%22179cb4e18f51f8-0f8d21d489e11-1f386252-232800-179cb4e18f6411%22%2C%221622611614%22%2C%22https%3A%2F%2Fworkbench.umeng.com%2F%22%2C%22workbench.umeng.com%22%5D; CNZZDATA1276392090=1355375287-1622611614-https%253A%252F%252Fworkbench.umeng.com%252F%7C1622611614; CNZZDATA30086426=cnzz_eid%3D733394678-1622610014-https%253A%252F%252Fworkbench.umeng.com%252F%26ntime%3D1622610014; CNZZDATA30069868=cnzz_eid%3D1334783879-1622611962-https%253A%252F%252Fworkbench.umeng.com%252F%26ntime%3D1622610403; _cnzz_CV30069868=%E6%98%AF%E5%90%A6%E7%99%BB%E5%BD%95%7C%E6%AD%A3%E5%B8%B8%E7%99%BB%E5%BD%95%7C1622642485273%26%E7%94%A8%E6%88%B7%E7%B1%BB%E5%9E%8B%7C%E7%AB%99%E9%95%BF%E7%94%A8%E6%88%B7%7C1622613686274; CNZZDATA30001831=cnzz_eid%3D601419121-1622611834-https%253A%252F%252Fworkbench.umeng.com%252F%26ntime%3D1622609968; cn_1276392090_dplus=1%5B%7B%7D%2C0%2C1622614440%2C0%2C1622614440%2Cnull%2C%22179cb4e18f51f8-0f8d21d489e11-1f386252-232800-179cb4e18f6411%22%2C%221622611614%22%2C%22https%3A%2F%2Fworkbench.umeng.com%2F%22%2C%22workbench.umeng.com%22%5D'
}
res = requests.get(url,headers=header)
with open('cnzz.html', 'w', encoding='utf-8') as file_obj:
file_obj.write(res.text)