我正试图为Selenium的下载设置一个新的下载文件夹,但遇到了一个错误。
我正在使用:
options.add_argument('download.default_directory = C:UsersUserDocumentsfolder')
错误我得到
File "C:/Users/GuilhermeMachado/PycharmProjects/untitled/Extranet_BTG.py", line 29
options.add_argument('download.default_directory = C:UsersUserDocumentsfolder')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 31-32: truncated UXXXXXXXX escape
它怎么了?
您需要将其作为dict
发送到add_experimental_option
,并且需要转义路径
options.add_experimental_option('prefs', {'download.default_directory': r'C:UsersUserDocumentsfolder'})