首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在使用Selenium时绕过Python3.6中的UnicodeEncodeError

在使用Selenium时绕过Python3.6中的UnicodeEncodeError
EN

Stack Overflow用户
提问于 2018-06-30 03:59:34
回答 1查看 24关注 0票数 0

我写了一个抓取程序,偶尔会遇到希腊字母“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)

有什么建议吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-06-30 04:55:38

尝试添加:

with open('combined_asset_info.csv', 'w', newline = '', encoding='cp1252') as myfile:

也许能行得通。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51108636

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档