表单 python 中的 Unicode 错误(使用 Mechanize)
Unicode error in python with forms (using Mechanize)
我正在尝试使用 Mechanize 读取网页中的一些表格:
for f in br.forms():
print f
并且出现以下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 42: ordinal not in range(128)
我想我需要转换一些字符,但我不知道该怎么做。
尝试转换为 repr、
for f in br.forms():
print repr(f)
我终于找到了解决办法:
import sys
reload(sys)
sys.setdefaultencoding('utf8')
我正在尝试使用 Mechanize 读取网页中的一些表格:
for f in br.forms():
print f
并且出现以下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 42: ordinal not in range(128)
我想我需要转换一些字符,但我不知道该怎么做。
尝试转换为 repr、
for f in br.forms():
print repr(f)
我终于找到了解决办法:
import sys
reload(sys)
sys.setdefaultencoding('utf8')