Python 为列表编码UTF-8
我使用selenium从javascript对象检索列表Python 为列表编码UTF-8,python,python-2.7,encoding,utf-8,Python,Python 2.7,Encoding,Utf 8,我使用selenium从javascript对象检索列表 search_reply = driver.find_element_by_class_name("ac_results") 尝试写入csv时,出现以下错误: Traceback (most recent call last): File "insref_lookup15.py", line 54, in <module> wr_insref.writerow(instrument_name) UnicodeEn
search_reply = driver.find_element_by_class_name("ac_results")
尝试写入csv时,出现以下错误:
Traceback (most recent call last):
File "insref_lookup15.py", line 54, in <module>
wr_insref.writerow(instrument_name)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 22: ordinal not in range(128)
及
但我只是得到了信息
AttributeError: 'xxx' object has no attribute 'encode'
您需要对列表中的元素进行编码:
csv
模块文档提供了一个更详细的Unicode对象编写方法,包括自动处理此操作的实用程序类。您需要对列表中的元素进行编码:
csv
模块文档提供了一个更详细的Unicode对象编写方法,包括自动处理此操作的实用程序类。您需要对列表中的元素进行编码:
csv
模块文档提供了一个更详细的Unicode对象编写方法,包括自动处理此操作的实用程序类。您需要对列表中的元素进行编码:
csv
模块文档提供了一个更详细的Unicode对象编写方法,包括自动处理此操作的实用程序类。驱动程序。按类名称查找元素返回什么?这是一张单子吗?这是一节课吗?我能推断出的肯定不是字符串。@Winterflags:列表中只有字符串对象吗?大概打印它会得到类似于[u'foo',u'bar',…]
@MartijnPieters是的,我得到[u'foo',u'bar',…]的东西。driver.find_element_by_class_name
返回什么?这是一张单子吗?这是一节课吗?我能推断出的肯定不是字符串。@Winterflags:列表中只有字符串对象吗?大概打印它会得到类似于[u'foo',u'bar',…]
@MartijnPieters是的,我得到[u'foo',u'bar',…]的东西。driver.find_element_by_class_name
返回什么?这是一张单子吗?这是一节课吗?我能推断出的肯定不是字符串。@Winterflags:列表中只有字符串对象吗?大概打印它会得到类似于[u'foo',u'bar',…]
@MartijnPieters是的,我得到[u'foo',u'bar',…]的东西。driver.find_element_by_class_name
返回什么?这是一张单子吗?这是一节课吗?我能推断出的肯定不是字符串。@Winterflags:列表中只有字符串对象吗?大概打印它会得到类似于[u'foo',u'bar',…]
@MartijnPieters是的,我得到[u'foo',u'bar',…]。
wr_insref.writerow(instrument_name).encode("utf-8")
AttributeError: 'xxx' object has no attribute 'encode'
wr_insref.writerow([v.encode('utf8') for v in instrument_name])