使用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)
#这样就可以了

解决utf8' codec can't decode byte 0xe5 in position 0: unexpected end of data的更多相关文章

  1. python错误:UnicodeDecodeError: 'utf8' codec can't decode byte 0xe6 in position 0: unexpected end of data

    一.错误原因 在学习selenium自动化测试框架的时候,进行模仿浏览器搜索功能,输入英文是没问题,但是输入中文就报错,报错代码 def test_baidu_search(self): " ...

  2. python join() 提示UnicodeDecodeError: 'utf8' codec can't decode byte 0xcb in position 0: unexpected end of的原因及解决办法

    问题: 在使用join()将列表元素连接成字符串时出错如下 return split.join(result) UnicodeDecodeError: 'utf8' codec can't decod ...

  3. 爬虫 -- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe6 in position 301: unexpected end of data

     errors参数有3个值:strict,  ignore,  replace html.decode("utf-8"),这种形式有时会报错,那么修改为下面形式,将decode函数 ...

  4. 解决Requests中文乱码【有用】,读取htm文件 读取txt文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0

    打开这个网址https://blog.csdn.net/chaowanghn/article/details/54889835 python在open读取txt文件时,出现UnicodeDecodeE ...

  5. Python3 解决 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

    Python3 解决 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte 一.问题 request.Reque ...

  6. 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

    'utf-8' codec can't decode byte 0xff in position 0: invalid start byte 觉得有用的话,欢迎一起讨论相互学习~Follow Me 今 ...

  7. 用python3读CSV文件,出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid con

    使用pd.read_csv()读csv文件时,出现如下错误: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd0 in position ...

  8. 【python-HTMLTestRunner】生成HTMLTestRunner报告报错ERROR 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

    [python-HTMLTestRunner]生成HTMLTestRunner报告报错:ERROR 'ascii' codec can't decode byte 0xe5 in position 0 ...

  9. 'utf-8' codec can't decode byte 0xc8 in position 0

    今天学习python中使用jieba库,遇到了错误:“UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0: i ...

随机推荐

  1. python装饰器实现登陆验证

    一: 定义有参数的装饰器 其中 CheckFileByName 是进行验证的过程 二: 登陆方法 三: 实现装饰调用

  2. Spring学习总结(19)——Spring概念详解

    Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson创建.简单来说,Spring是一个分层的JavaSE/EEfull-stack(一 ...

  3. CodeForcesGym 100641B A Cure for the Common Code

    A Cure for the Common Code Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on  ...

  4. Cannot Allocate New Log

    http://www.itpub.net/thread-1842569-1-1.html http://czmmiao.iteye.com/blog/2277675

  5. java cocurrent包

    1. java.util.concurrent - Java 并发工具包 Java 5 添加了一个新的包到 Java 平台,java.util.concurrent 包.这个包包含有一系列能够让 Ja ...

  6. 关于server和虚拟主机的差别

    文章都是先由本人个人博客,孙占兴:www.teilim.com,先更新,随后CSDN博客才会更新.掌握第一动态请关注本人主站. 原文链接:http://www.teilim.com/guan-yu-y ...

  7. 《coredump问题原理探究》Linux x86版7.8节vector相关的iterator对象

    在前面看过了一个vectorcoredump的样例,接触了vector的iterator,能够知道vector的iterator仅仅有一个成员_M_current指向vector某一个元素. 先看一个 ...

  8. ContextMenu的使用具体解释

    二话不说,先上图: 能够非常easy看到这是一个类似于Dialog悬浮在活动上的控件,它是由被注冊的view长按所触发的. 当然啦,也有其它的实现方式,这里就先介绍一下系统的ContextMenu:( ...

  9. SOA概念具体解释

    1.概述 1.1基本定义 SOA(Service-Oriented Architecture)既面向服务的体系结构,是一个组件模型.它将应用程序猿的不同功能可是(称为服务)通过定义良好的接口联系起来. ...

  10. 2016.02.23,英语,《Vocabulary Builder》Unit 01

    Bell:来源于拉丁语,含义为war.fight,其中Bellona [bә'lәunә]是罗马女战神的名字,她的丈夫是战神Mars.antebellum: [ˌænti'beləm] adj. 战前 ...