判断爬取到页面的编码类型

一个很有趣的个人博客,不信你来撩 fangzengye.com



 1 #如果你的python没有安装chardet模块,你需要首先安装一下chardet判断编码的模块哦 
2 #author:pythontab.com
3 import chardet
4 import urllib
5 #先获取网页内容
6 data1 = urllib.urlopen('http://www.baidu.com').read()
7 #用chardet进行内容分析
8 chardit1 = chardet.detect(data1)
9
10 print chardit1['encoding'] # baidu

https://www.cnblogs.com/huochaihe/p/8366514.html

posted @ 2020-09-13 14:53  开源的Boy  阅读(79)  评论(0)    收藏  举报