您的位置:首页 > 编程语言 > Python开发

python chardet模块 检测文档编码

2017-01-01 22:25 453 查看
python chardet模块 检测文档编码

想知道文档、网页的编码,可以使用python的chardet模块,如下:
import chardet
import urllib2
theresult = urllib2.urlopen(url = 'www.baidu.com').read()

print chardet.detect(theresult)
输出结果 {'confidence': 0.99, 'encoding': 'GB2312'}

意思是网页编码有99%的可能性是gb2312
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: