首页 > 解决方案 > Selenium 错误:“chromedriver”可执行文件需要在 PATH 中

问题描述

我在运行 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 二进制文件位于指定位置。当我运行 pythonscraper.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

标签: pythonseleniumselenium-webdriver

解决方案


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

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

推荐阅读