#-*- coding utf-8 -*-
import urllib.request
response = urllib.request.urlopen('http://www.baidu.com')
html = response.read()
#print(type(html))
#这里读到的内容html是bytes类型,中文有问题
htmlStr = str(html,'gbk')
print(htmlStr)

f = open('baidu.html','w')
f.write(htmlStr)
f.close()

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

et_highlighter