当我运行这段代码时:
from selenium import webdriver
import time
driver = webdriver.Chrome('C:/Program Files
(x86)/Google/Chrome/Application/chrome.exe')
driver.get('https://www.google.com/')
它只会打开我的浏览器,但不会打开作为参数传递给driver.get()
的 URL。
下面是回溯:
Traceback (most recent call last):
File "C:UsersefiqqOneDrivePlochaPythonLink.py", line 4, in <module>
driver = webdriver.Chrome('C:/Program Files (x86)/Google/Chrome/Application/chrome.exe')
File "C:UsersefiqqAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdriverchromewebdriver.py", line 68, in __init__
self.service.start()
File "C:UsersefiqqAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdrivercommonservice.py", line 98, in start
self.assert_process_still_running()
File "C:UsersefiqqAppDataLocalProgramsPythonPython36-32libsite-packagesseleniumwebdrivercommonservice.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:/Program Files (x86)/Google/Chrome/Application/chrome.exe unexpectedly exited. Status code was: 0
你必须通过的路径不是chrome.exe
。你必须指向chromedriver.exe
;
你可以在这里得到它:http://chromedriver.chromium.org/downloads