页面显示如下图:
pycharm 查看:
网页中需要设置 charset=utf-8
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
python 写入文件的时候 控制为 utf-8:
from urllib.request import urlopen
url = "http://www.baidu.com"
resp = urlopen(url)
# encoding='utf-8'
with open("mybaidu.html", mode="w", encoding='utf-8') as f:
f.write(resp.read().decode("utf-8"))
pycharm 设置 File Encodings :
登登,显示正常了:
网友评论