In [3]: from chardet.universaldetector import UniversalDetector
In [4]: uso = urllib.urlopen('http://www.baidu.com/') ...: det = UniversalDetector() ...: for line in uso.readlines(): ...: det.feed(line) ...: if det.done: ...: break ...: det.close() ...: uso.close() ...: det.result ...: Out[4]: {'confidence': 0.99, 'encoding': 'utf-8', 'language': ''}