您的位置:首页 > 编程语言 > Python开发

python抓取网页编码问题

2017-01-13 15:22 211 查看
抓取的网页如果包含中文,那么正确打印和保存网页就需要解码和编码

import urllib

url = 'http://example.com/'
html = urllib.urlopen(url).read()
unicode = html.decode("utf-8")
gbkcode = unicode.encode("gbk")
print(gbkcode)
f = open("hello.txt", "w")
f.write(gbkcode)
f.close
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: