`
john2007
  • 浏览: 76301 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

自动检测文件编码

阅读更多

对于抓取的网页处理时,我们往往要判断它的字符编码,今天发现了python的一个自动判断编码的lib,特与众分享.

名称:chardet

介绍:Character encoding auto-detection in Python 2 and 3. As smart as your browser. Open source.

 

下载地址:

http://pypi.python.org/pypi/chardet/1.0.1

文档地址:

http://chardet.feedparser.org/docs/index.html

 

文档目录:

 

 

basic usage:
>>> import urllib
>>> rawdata = urllib.urlopen('http://yahoo.co.jp/').read()
>>> import chardet
>>> chardet.detect(rawdata)
{'encoding': 'EUC-JP', 'confidence': 0.99}

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics