python 报错'gbk' codec can't encode character 'ue5d1' in position 0:

2019-02-14 11:49:21 浏览数 (1)

代码语言:javascript复制
在网络怕爬虫过程中遇到,编码错误
代码语言:javascript复制
'gbk' codec can't encode character 'ue5d1' in position 0: illegal multibyte sequence
代码语言:javascript复制
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()
代码语言:javascript复制
代码语言:javascript复制
代码语言:javascript复制
修改部分
代码语言:javascript复制
代码语言:javascript复制
file = open(file_path, 'w')增加
代码语言:javascript复制
encoding='utf-8'
代码语言:javascript复制
即  file =open(file_path,'w',encoding='utf-8')
代码语言:javascript复制

0 人点赞