selenium报错信息-- Python 中 ‘unicodeescape‘ codec can‘t decode bytes in position XXX: trun错误解决方案

本以为是缺少utf-8造成的错误,但是加完这个还是报错,于是在网上百度了一下是因为上传的路劲粗无偶导致的

正确的写法是把路劲中“\”变为“\\”,或者在路劲的开头加上“r”,或者在路劲的开头加上“r”并且把“\”变为“/”

如下:

1、os.system('C:\\Users\\fyr\\Desktop\\auit.exe')

2、os.system(r'C:\Users\fyr\Desktop\auit.exe')

3、os.system(r'C:/Users/fyr/Desktop/auit.exe')

具体原因:

window读取文件可以用"\",但是在字符串中“\”是被当作转义字符来使用。

解决办法:

Python中描述路劲时可以有多种方式,以下是常见的三种:

   1、转义的方式

'd:\\a.txt'
2、显式声明字符串不用转义

'd:r\a.txt'

3、使用Linux的路径

'd:/a.txt'
在linux和window下都可以用第三种

猜你喜欢

转载自blog.csdn.net/qq_72290695/article/details/134609744
今日推荐