对此非常陌生,我无法让chromedriver或geckodriver工作。他们都位于/usr/local/bin/
。所以我知道他们在PATH。
我的代码:
from selenium import webdriver
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
driver.get('http://www.google.com/xhtml');
这是我得到的回报:
Traceback (most recent call last): File "11.py", line 3, in <module>
driver = webdriver.Chrome('Desktop/chromedriver') # Optional argument, if not specified will search path. File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 81, in start
os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
你必须通过ChromeDriver
的绝对路径和Attribute Key
如下:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
driver.get('http://www.google.com');