#/usr/bin/env python
#-*- coding:utf-8 -*-

import urllib2
import sys
import chardet

req = urllib2.Request("http://tycool.top/")
content = urllib2.urlopen(req).read()
typeEncode = sys.getfilesystemencoding()##系统默认编码
infoencode = chardet.detect(content).get('encoding','utf-8')##通过第3方模块来自动提取网页的编码
html = content.decode(infoencode,'ignore').encode(typeEncode)##先转换成unicode编码,然后转换系统编码输出
print html

转载于:https://www.cnblogs.com/tyzZ001/p/5958829.html

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐