我写了一个抓取程序,偶尔会遇到希腊字母“u”:
Traceback (most recent call last):
File "<ipython-input-1-64e1ce177c3a>", line 1, in <module>
runfile('C:/Users/jmiller/Desktop/MasterControl Scraping/Project_TEST.py', wdir='C:/Users/jmiller/Desktop/MasterControl Scraping')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/jmiller/Desktop/MasterControl Scraping/Project_TEST.py", line 271, in <module>
writer.writerow(row)
File "C:\ProgramData\Anaconda3\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u03bc' in position 166: character maps to <undefined>
我读到我应该使用utf-8,但我的Python程序已经在用utf-8编码了,所以我不确定还能在哪里指定:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 13 09:45:52 2018
@author: jmiller
"""
编辑:完成后,我会将其全部写入csv文件:
with open('combined_asset_info.csv', 'w', newline = '') as myfile:
writer = csv.writer(myfile, delimiter = ',')
for row in combined_asset_info:
writer.writerow(row)
有什么建议吗?谢谢
发布于 2018-06-30 04:55:38
尝试添加:
with open('combined_asset_info.csv', 'w', newline = '', encoding='cp1252') as myfile:
也许能行得通。
https://stackoverflow.com/questions/51108636
复制相似问题