当我使用Selenium打开Chrome的新实例时,我无法再打开网站了。我的代码目前相当简单:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\User Data')
driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\Google\\Chrome\\chromedriver.exe', chrome_options=options)
driver.get('http://www.google.com')
Chrome已打开,我的个人资料已加载,但没有任何反应,我收到以下错误:
Traceback (most recent call last):
File "C:/Users/Admin/Dropbox/Python/test.py", line 5, in <module>
driver = webdriver.Chrome(executable_path='C:\\Program Files (x86)\\Google\\Chrome\\chromedriver.exe', chrome_options=options)
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 67, in __init__
desired_capabilities=desired_capabilities)
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 90, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 177, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python35\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
(Driver info: chromedriver=2.9.248315,platform=Windows NT 6.3 x86_64)
现在,如果我没有将其设置为打开默认配置文件,那么一切都按预期工作:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.google.com')
我的chromedriver.exe位于executable_path所在的位置,但我也将其设置为环境变量。我不认为我在第一个代码中需要executable_path参数,但不确定。
有谁知道driver.get()不起作用的原因是什么?