代码之家  ›  专栏  ›  技术社区  ›  Username

Selenium错误:“chromedriver”可执行文件需要位于路径[duplicate]中

  •  -1
  • Username  · 技术社区  · 7 年前

    我的电脑上有运行Debian9的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")
    

    铬二元在指定位置。当我运行python时 刮刀.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 回复  |  直到 7 年前
        1
  •  2
  •   ergesto    7 年前

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

    driver = webdriver.Chrome(executable_path='/path/to/driver/chromedriver')
    
        2
  •  1
  •   R Balasubramanian    7 年前

    您的浏览器二进制文件(在本例中,用于 chromium chromedriver . 例如,仅仅拥有二进制文件就意味着您可以自己启动chromium,但是webdrivers将无法启动自己的chrom(e/ium)实例,从而阻止您对它们使用selenium。解决方法是在路径上的文件夹中下载您选择的chromedriver可执行文件(注意版本可能很重要),或者在创建webdriver时直接提供路径。