【发布时间】:2017-01-15 19:19:17
【问题描述】:
我想打开谷歌浏览器,就像它本身一样,chromedriver 在没有我的 cookie、密码、历史记录和所有员工的情况下打开它。 我尝试使用该选项,并在整个网络上搜索解决方案, 一个都没有 另外我试过了
从硒导入网络驱动程序 从 selenium.webdriver.common.keys 导入密钥 从 selenium.webdriver.chrome.options 导入选项
opt = webdriver.ChromeOptions()
opt.add_arguments("--user-data-dir=C:\Users\Bar\AppData\Local\Google\Chrome\User Data")
driver = webdriver.Chrome(opt)
driver.get("https://www.google.com/")
但它没有工作它说:
C:\Users\Bar\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Bar/PycharmProjects/yad2/Webdriver.py
File "C:/Users/Bar/PycharmProjects/yad2/Webdriver.py", line 7
opt.add_arguments("--user-data-dir=C:\Users\Bar\AppData\Local\Google\Chrome\User Data")
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 18-19: truncated \UXXXXXXXX escape
Process finished with exit code 1
【问题讨论】:
-
省略
--并尝试使用opt.add_arguments("user-data-dir=C:\Users\Bar\AppData\Local\Google\Chrome\User Data") -
@SaurabhGaur 同样的错误:\
-
我试图将 r 放在字符串之前以使其成为原始字符串,它现在如下所示:
Traceback (most recent call last): File "C:/Users/Bar/PycharmProjects/yad2/Webdriver.py", line 6, in <module> opt.add_arguments(r"user-data-dir=C:\Users\Bar\AppData\Local\Google\Chrome\User Data") AttributeError: 'Options' object has no attribute 'add_arguments' -
@SaurabhGaur 我决定将用户数据复制到项目文件夹中,而且我的参数有误s,应该是没有s的参数新问题:pastebin.com/Fr35Ph4y
-
我已经提供了它作为答案,试试这个并让我知道..:)
标签: python selenium selenium-webdriver