python中的chardet模块

chardet模块使用

chardet模块可用来猜测指定内容的编码类型, 参数接收bytes类型.

import chardet
import requests

url = "https://www.baidu.com"
resp = requests.get(url)
# detect() 接受bytes类型. 返回一个字典, 里面有观察后的页面编码类型.
compare_encoding = chardet.detect(resp.content).get('encoding')

猜你喜欢

转载自blog.csdn.net/One_of_them/article/details/82012077
今日推荐