正文
解决utf8' codec can't decode byte 0xe5 in position 0: unexpected end of data
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
使用unicode对象的话,除了这样使用u标记,还可以使用unicode类以及字符串的encode和decode方法。
unicode类的构造函数接受一个字符串参数和一个编码参数,将字符串封装为一个unicode,比如在这里,由于我们用的是utf-8编码,所以unicode中的编码参数使用’utf-8′将字符封装为unicode对象,然后正确输出到控制台:
i = '多大2%2大沙地'
driver.find_element_by_id('search').send_keys(i)
#会报错icodeDecodeError: 'utf8' codec can't decode byte 0xe5 in position 0: unexpected end of data i = '多大2%2大沙地'
a = unicode(i, 'utf-8')
driver.find_element_by_id('search').send_keys(a)
#这样就可以了