摘要: from:http://www.unixresources.net/linux/clf/python/archive/00/00/42/73/427317.html结合二位的答复,运行结果如下: >>> a='中国' >>> b=unicode(a, 'cp936') >>> b u'u4e2du56fd' >>> c = b.encode('utf-8') >>> c 'xe4xb8xadxe5x9bxbd' >> 阅读全文
posted @ 2011-03-02 17:17 dkcndk 阅读(990) 评论(0) 推荐(0) 编辑
摘要: 法一:isinstance(s, str) 用来判断是否为一般字符串isinstance(s, unicode) 用来判断是否为unicode或if type(str).__name__!="unicode":str=unicode(str,"utf-8")else:pass法二:Python chardet 字符编码判断使用 chardet 可以很方便的实现字符串/文件的编码检测。尤其是中文网页,有的页面使用GBK/GB2312,有的使用UTF8,如果你需要去爬一些页面,知道网页编码很重要的,虽然HTML页面有charset标签,但是有些时候是不对的。 阅读全文
posted @ 2011-03-02 02:36 dkcndk 阅读(80632) 评论(1) 推荐(2) 编辑