>>> import urllib
>>> urlread = lambda url: urllib.urlopen(url).read()
>>> import chardet
>>> chardet.detect(urlread("http://google.cn/"))
{'encoding': 'GB2312', 'confidence': 0.99}
>>> chardet.detect(urlread("http://yahoo.co.jp/"))
{'encoding': 'EUC-JP', 'confidence': 0.99}
>>> chardet.detect(urlread("http://amazon.co.jp/"))
{'encoding': 'SHIFT_JIS', 'confidence': 1}
>>> chardet.detect(urlread("http://pravda.ru/"))
{'encoding': 'windows-1251', 'confidence': 0.9355}
>>> chardet.detect(urlread("http://auction.co.kr/"))
{'encoding': 'EUC-KR', 'confidence': 0.99}
>>> chardet.detect(urlread("http://haaretz.co.il/"))
{'encoding': 'windows-1255', 'confidence': 0.99}
>>> chardet.detect(urlread("http://www.nectec.or.th/tindex.html"))
{'encoding': 'TIS-620', 'confidence': 0.7675}
>>> chardet.detect(urlread("http://feedparser.org/docs/"))
{'encoding': 'utf-8', 'confidence': 0.99}
Great to know!
Showing posts with label Mark Pilgrim. Show all posts
Showing posts with label Mark Pilgrim. Show all posts
Monday, July 20, 2009
Dive Into Mark: Universal Encoding Detector
Character encoding auto-detection in Python 2 and 3. As smart as your browser. Open source.
More great open-source code from Mark Pilgrim.
Monday, June 15, 2009
Dive Into Python 3 - httplib2
Fantastic writing on a fine HTTP library "httplib2" by Mark Pilgrim.
Dive Into Python 3 - HTTP Web Services
Shows the value of the feature set of HTTP - compression, caching, getting around local and third-party caches, temporary and permanent redirects. "httplib2" supports them all, by default, so you can be a good HTTP-Citizen from the word GO.
I read the Reddit comments on this article, and it was pretty depressing. There is a weird reaction to a well designed piece of library code - the better designed and more comprehensive a library is, the more vocal and numerous the irrational criticism for it is.
Image via Wikipedia
Image via Wikipedia
Image via Wikipedia
Labels:
Dive Into Python,
HTTP,
httplib2,
Mark Pilgrim,
Python
Subscribe to:
Posts (Atom)