import requests
import chardet
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186
Safari/537.36',
}
response = requests.get('http://www.baidu.com/',headers =headers )
# print response.content
判断网页的编码类型
print chardet.detect(response.content)['encoding']
# print chardet.detect(response.content)
结果:
>> utf-8