赞
踩
import requests
res = requests.get("https://www.baidu.com/")
res.encoding = res.apparent_encoding
print(res.text)
import requests
res = requests.get("https://www.baidu.com/")
txt = res.content.decode('gbk')
import requests
import chardet
res = requests.get("https://www.baidu.com/")
encoding = chardet.detect(res.content)['encoding']
print(res.content.decode(encoding))
import requests
import cchardet
res = requests.get("https://www.baidu.com/")
encoding = cchardet.detect(res.content)['encoding']
print(res.content.decode(encoding))
import requests
import cchardet
res = requests.get("https://www.baidu.com/")
res_encoding = res.encoding # 响应的编码方式
con_encoding = cchardet.detect(res.content)['encoding'] # 内容的编码方式
print(res.text.encode(res_encoding).decode(con_encoding)) # 重新编解码text
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。