Selenium错误:“ chromedriver”可执行文件必须位于PATH中

时间:2018-07-05 20:37:51

标签: python selenium selenium-webdriver

运行Debian 9的计算机上装有Chromium。这里是scraper.py

from selenium import webdriver
import time

options = webdriver.ChromeOptions()
options.add_argument("--ignore-certificate-errors")
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"

driver = webdriver.Chrome(chrome_options=options)
driver.get("https://python.org")

Chromium二进制文件位于指定位置。当我运行python scraper.py时,出现此错误。

Traceback (most recent call last):
  File "scraper.py", line 9, in <module>
    driver = webdriver.Chrome(chrome_options=options)
  File "/home/me/ENV/pbc_vss/local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/home/me/ENV/pbc_vss/local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 83, 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

2 个答案:

答案 0 :(得分:2)

指定您的Chrome驱动程序所在的路径,下载页面https://sites.google.com/a/chromium.org/chromedriver/downloads

driver = webdriver.Chrome(executable_path='/path/to/driver/chromedriver')

答案 1 :(得分:1)

您的浏览器二进制文件(在本例中为chromium)与您的chromedriver不同。例如,仅拥有二进制文件就意味着您可以自己启动Chrome,但Web驱动程序将无法启动自己的chrom(e / ium)实例,从而阻止您将硒与它们一起使用。解决方案是在路径上的文件夹中下载您选择的chromedriver可执行文件(请注意版本可能很重要),或者在创建Webdriver时直接提供路径。