ITPub博客

首页 > IT职业 > IT职场 > python 报错

python 报错

IT职场 作者:micromad 时间:2021-09-09 09:30:56 0 删除 编辑


在网络怕爬虫过程中遇到,编码错误
'gbk' codec can't encode character 'ue5d1' in position 0: illegal multibyte sequence
response = requests.get(url)
html_uid = response.text
# name=html_uid["result"]['name']
# path = "E:\python_py\景区详情\省份\吉林省\"#文件路径"
file_path =cities_folder+province+city+'_'+str(i)+"_"+str(j)+'.json'
file = open(file_path, 'w')
file.writelines(html_uid)
file.close()


修改部分

file = open(file_path, 'w')增加
encoding='utf-8'
即  file =open(file_path,'w',encoding='utf-8')


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2763/viewspace-2804212/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: Webflux快速入门
请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    75
  • 访问量
    576