One - One Code All

Blog Content

python3用chardet查看文本编码

Python   2014-06-24 11:15:56
#coding=utf-8
import urllib.request
import chardet
url = 'http://www.baidu.com'

a = urllib.request.urlopen(url)

'''
chardet模块
使用该模块可以查看字符串的编码格式:chardet.detect()
'''
encode = chardet.detect(a.read())
print(encode['encoding'])

#假设存在一个a.txt的文件
f = open('a.txt', 'rb')
print(chardet.detect(f.read(100)))



上一篇:python3解析JSON之demjson
下一篇:airflow backfill用法

The minute you think of giving up, think of the reason why you held on so long.