奇怪,之前发的博文中内容怎么没有了。最近刚开始用csdn,发现经常丢东西,不明白。。
import urllib.request
url = 'http://www.baidu.com'
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
data = response.read()
datautf = data.decode('UTF-8')
fo = open('log.html', 'w',encoding='utf-8')
fo.write(datautf)
fo.close()
text = open('log.html', encoding='utf8').read()
print(text.encode('utf8'))
至此,Python3 中 print 问题解决。