import chardet
s = 'ä½\xa0好' # 假设你有一段乱码的字符串
b = s.encode('raw_unicode_escape') # 转为bytes对象
result = chardet.detect(b) print(result) # 检测编码方式
# 输出:{'encoding': 'utf-8', 'confidence': 0.99, 'language': ''}
#转为中文
b = b.decode('utf-8')
import chardet
s = 'ä½\xa0好' # 假设你有一段乱码的字符串
b = s.encode('raw_unicode_escape') # 转为bytes对象
result = chardet.detect(b) print(result) # 检测编码方式
# 输出:{'encoding': 'utf-8', 'confidence': 0.99, 'language': ''}
#转为中文
b = b.decode('utf-8')