python之chardet用来检测字符串编码的

import chardet

a=b'xe4xbdxa0xe5xa5xbdxefxbcx8cxe4xb8x96xe7x95x8cxe3x80x82'
print(chardet.detect(a)) # {'encoding': 'utf-8', 'confidence': 0.99, 'language': ''}
print(a.decode('utf-8')) # 你好,世界。
这个模块多用于跨语言得到结果,或者爬虫
原文地址:https://www.cnblogs.com/mmyy-blog/p/11889221.html