第三方模块-chadet(检测编码)

一、下载  pip3 install chardet

# 检测编码工具 字符串越多越准确
import chardet

print(chardet.detect(b'hello world!'))
# {'encoding': 'ascii', 'confidence': 1.0, 'language': ''} confidence 检测概率 1.0=100%

print(chardet.detect('同一个世界,同一个梦想'.encode('gbk')))

# {'encoding': 'GB2312', 'confidence': 0.99, 'language': 'Chinese'}

print(chardet.detect('我想要怒放的生命'.encode('utf-8')))
# {'encoding': 'utf-8', 'confidence': 0.99, 'language': ''}

print(chardet.detect(b'\xc0\xeb\xc0\xeb\xd4\xad\xc9\xcf\xb2\xdd\xa3\xac\xd2\xbb\xcb\xea\xd2\xbb\xbf\xdd\xc8\xd9'))
# {'encoding': 'GB2312', 'confidence': 0.7407407407407407, 'language': 'Chinese'}
posted @ 2019-08-02 10:31  桑铎是大叔  阅读(270)  评论(0)    收藏  举报