每个网页获取时的编码不同,每次用浏览器打开查看的效率较低,requests里有提供方法直接使用网页默认编码。
如下
import requests
url="http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/"
res=requests.get(url)
print(res.encoding)
res.encoding=res.apparent_encoding
print(res.encoding)
print(res.text)