<script type="text/javascript">
if(document.charset){
alert(document.charset+"!!!!");
document.charset = 'GBK';
alert(document.charset);
}
else if(document.characterSet){
alert(document.characterSet+"????");
document.characterSet = 'GBK';
alert(document.characterSet);
}
import urllib
rawdata = urllib.urlopen('http://www.1sucai.cn/').read()
import chardet
chardet.detect(rawdata)
{'confidence': 0.99, 'encoding': 'GB2312'}
import chardet
a='abc'
type(a)
str
chardet.detect(a)
{'confidence': 1.0, 'encoding': 'ascii'}
a ="我"
chardet.detect(a)
{'confidence': 0.73, 'encoding': 'windows-1252'}
a.decode('windows-1252')
u'\xe6\u02c6\u2018'
chardet.detect(a.decode('windows-1252').encode('utf-8'))
type(a.decode('windows-1252'))
unicode
type(a.decode('windows-1252').encode('utf-8'))
str
chardet.detect(a.decode('windows-1252').encode('utf-8'))
{'confidence': 0.87625, 'encoding': 'utf-8'}
a ="我是中国人"
type(a)
str
{'confidence': 0.9690625, 'encoding': 'utf-8'}
chardet.detect(a)
# -*- coding:utf-8 -*-
import chardet
import urllib2
#抓取网页html
html = urllib2.urlopen('http://www.1sucai.cn/').read()
print html
mychar=chardet.detect(html)
print mychar
bianma=mychar['encoding']
if bianma == 'utf-8' or bianma == 'UTF-8':
html=html.decode('utf-8','ignore').encode('utf-8')
else:
html =html.decode('gb2312','ignore').encode('utf-8')
print html
print chardet.detect(html)
# -*- coding:utf-8 -*- print '中文'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有