【问题标题】:Chromedriver: "FileNotFoundError: [WinError 2] The system cannot find the file specified" ErrorChromedriver:“FileNotFoundError:[WinError 2]系统找不到指定的文件”错误
【发布时间】:2017-08-01 23:46:01
【问题描述】:

一直在寻找答案,但找不到任何东西。似乎坚持说它找不到指定的文件,然后检查 PATH,但即使这样也看不到它:/ 我已将目录放入 PATH:http://imgur.com/a/ZP59w

程序:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com/")

错误:

Traceback (most recent call last):
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-       packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-  32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-     32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "H:\temp.py", line 2, in <module>
    driver = webdriver.Chrome()
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\site-   packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Users\dilri\AppData\Local\Programs\Python\Python36-32\lib\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

如果有人能提供帮助,将不胜感激。

【问题讨论】:

    标签: python selenium-chromedriver


    【解决方案1】:

    您可以尝试直接将路径传递给它。

    所以我的桌面上有 webdriver 文件,所以:

    webdriver.Chrome('C:/Users/adam/Desktop/chromedriver.exe')
    

    可以获取webdriverhere.

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,用Options方法解决了。

      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      options = Options()
      options.binary_location = "C:\Program Files (x86)\Google\Chrome Dev\Application\chrome.exe"
      driver = webdriver.Chrome(chrome_options=options, executable_path=r"C:\Program Files (x86)\Google\chromedriver.exe", )
      driver.get("https://www.google.com/")
      

      希望它能解决你的问题。

      【讨论】:

        【解决方案3】:

        您可以使用以下内容:

        from selenium import webdriver
        
        browser = webdriver.Chrome(r"*your path here*")
        

        如何获取路径? 如果在 Windows 系统上转到 webdriver 的提取位置,请按 shift 键并选择 Copy as Path

        enter image description here

        【讨论】:

          猜你喜欢
          • 2019-07-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-05-28
          • 2018-05-21
          • 1970-01-01
          • 1970-01-01
          • 2020-01-02
          相关资源
          最近更新 更多