response = requests.get('ur;', params=params, cookies=cookies, headers=headers, verify=False)
if response.status_code == 200:
# 尝试使用不同的编码解码响应内容
possible_encodings = ['utf-8', 'ISO-8859-1', 'cp1252', 'gb2312']
for encoding in possible_encodings:
try:
response_text = response.content.decode(encoding)
print(f"成功使用编码 {encoding} 解码响应内容:\n{response_text}")
break # 如果成功解码,就不再尝试其他编码
except UnicodeDecodeError:
continue # 如果解码失败,尝试下一个编码
# 如果上述编码都无法解码,可以添加更多可能的编码
else:
print(f"请求失败,状态码为{response.status_code}")
response.close()
标签:编码,cookies,code,encoding,解码,爬虫,response
From: https://www.cnblogs.com/code3/p/17722074.html