python转换字符集
2018-07-20 来源:open-open
def URLtoUTF8(string):
""""""
g_code_type = ['utf-8', 'utf8', 'gb18030', 'gb2312', 'gbk', 'ISO-8859-2']
try:
tmp = urllib.unquote(str(string))
code = chardet.detect(tmp)['encoding']
try:
g_code_type.index(code.lower())
tmp = tmp.decode(code)
except:
try:
tmp = tmp.decode('utf8')
except:
tmp = tmp.decode('gb18030')
except:
tmp = json.dumps(string)
tmp = tmp.replace(u'"','')
pass
tmp = tmp.replace(u'\xa0',' ')
return tmp
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:php上传图片代码演示
下一篇:PHP上传图片代码
最新资讯
热门推荐