解决诸如æ´å¤äº§å乱码
方案一:在响应对象前加入response.encoding='utf-8',例如
response.encoding='utf-8'
print(response.text)
一般通过以上代码可以解决大部分的乱码。
方案二:通过chardet分析二进制响应数据的编码类型,让response.encoding=’求得编码格式‘生效,最后解决乱码问题,例如:
import chardet
response是响应对象
response.encoding=chardet.detect(response.content)['encoding']
print(response.text)
最后提一点用处不大的,如果你应付的是老式网站,如下简洁代码可能帮上忙:
reponse.encode('iso-8859-1').decode('gbk')
感谢您的观看