- 错误代码
import requests
url = 'https://blog.csdn.net/nanhuaibeian/article/details/85802919'
response = requests.get(url)
response.encoding = 'utf-8'
with open('real_case.html','w') as f:
f.write(response.text)
运行结果:
2. 修改后
import requests
url = 'https://blog.csdn.net/nanhuaibeian/article/details/85802919'
response = requests.get(url)
#将编码写入open函数
with open('real_case.html','w',encoding='utf-8') as f:
f.write(response.text)
- 同样的代码,运行在Linux下,啥事都没有,所以还是建议大家 使用Linux。