【问题标题】:Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on MacSelenium 在 Mac 上给出“selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件”
【发布时间】:2018-02-12 02:20:42
【问题描述】:

尝试让selenium 与 Python 3 一起用于网络抓取:

from selenium import webdriver
chrome_path = r"/Library/Frameworks/Python.framework/Versions/3.6/bin/chromedriver"
driver = webdriver.Chrome(chrome_path)

我收到以下错误消息:

selenium.common.exceptions.WebDriverException:消息:未知错误:找不到 Chrome 二进制文件

here 解决了一个类似的问题,但令我困惑的是 Chrome 已经安装在我的系统上。另一个提问者显然没有在他们的计算机上。我正在运行最新版本的 Mac OS。

【问题讨论】:

  • 您使用的是哪个版本的 chrome?请附上您的问题版本的屏幕截图
  • 版本 60.0.3112.113
  • 你的 chrome 安装在哪个路径上?
  • 文件存储在:/Users/alex/Desktop

标签: python python-3.x macos selenium


【解决方案1】:

问题是 chromedriver 还需要知道 chrome 在哪里。在您的情况下,它位于非默认路径。所以你需要指定Google Chrome二进制文件的完整路径。

options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
chrome_driver_binary = "/usr/local/bin/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)

上面的代码是你应该使用的

【讨论】:

    【解决方案2】:

    我在学习硒时遇到了这个烦人的问题。 这是我的解决方案:(MacOS 10.13.4)

    1. 卸载我的 chrome
    2. 使用自制安装chromedriver:brew cask install chromedriver
    3. 使用自制安装chrome:brew cask install google-chrome

    感谢 homebrew 现在 chrome 和 chromedriver 安装在同一个文件夹中,这个问题将自动解决。

    【讨论】:

    • 2021 年,只需 brew install google-chrome 就可以了。
    【解决方案3】:

    在Win上设置chrome.exe的名称很重要,否则无法创建进程(见下文):

      from selenium import webdriver
      from webdriver_manager.chrome import ChromeDriverManager
    
      options = webdriver.ChromeOptions()
      options.binary_location = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
      chrome_driver_binary = r"C:/Users/Max/.wdm/chromedriver/75.0.3770.8/win32/chromedriver.exe"
      driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
      driver.get('http://web.whatsapp.com')
    

    selenium.common.exceptions.WebDriverException:消息:未知错误:无法创建 Chrome 进程。

    对于 Firefox(下载驱动程序https://github.com/mozilla/geckodriver/releases):

      options = webdriver.FirefoxOptions()
      #options.add_argument('-headless')
      #options.binary_location = r"C:\maxbook\maxboxpython\geckodriver-v0.24.0-win64\geckodriver.exe"
      options.binary_location = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
      firefox_driver_binary = r"C:\maxbook\maxboxpython\geckodriver-v0.24.0-win64\\"
      driver = webdriver.Firefox(firefox_driver_binary, options=options)
    

    【讨论】:

      【解决方案4】:
      options = webdriver.ChromeOptions()
      options.binary_location = r"<YOUR_CHROME_PATH>\chrome.exe"
      chrome_driver_path = r"<PATH_TO_CHROME_DRIVER>\chromedriver.exe>"
      
      browser = webdriver.Chrome(chrome_driver_path, chrome_options=options)
      

      【讨论】:

      • 更多解释将对 OP 有所帮助。
      • @Kyle Mar 请见下文。
      【解决方案5】:

      如果有人在 linux 机器上遇到同样的错误,那么您缺少 google chrome 安装作为 chrome 驱动程序工作所需的步骤之一。

      关注this link 在 Linux 上安装 Google chrome。

      现在,检查代码

      driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', options=chrome_options, service_args=['--verbose', '--log-path=/tmp/chromedriver.log'])
      

      对我来说它有效。

      【讨论】:

        【解决方案6】:

        如果您的 chromedriver 位于 /Library/Frameworks/Python.framework/Versions/3.6/bin/ 目录中,则以下代码块应该适合您:

        from selenium import webdriver
        
        chrome_path = r'/Library/Frameworks/Python.framework/Versions/3.6/bin/chromedriver'
        driver = webdriver.Chrome(executable_path=chrome_path)
        driver.get('https://www.google.co.in')
        

        【讨论】:

          【解决方案7】:

          在我的情况下,我安装了 Chrome 浏览器,然后它不会抛出错误。

          【讨论】:

            【解决方案8】:

            article 提供了正在发生的事情的完整细分。安装最新的网络驱动程序应该可以解决问题,而不是更改代码。

            基本上 85 版的 chrome 安装在不同的位置,但这只会影响新安装,因此对大多数人来说并不明显。

            最新的网络驱动程序了解新位置,因此获取更新的驱动程序是最简单的解决方案 - 当然,除非您特别需要测试旧版本。

            Location of drivers.

            【讨论】:

              【解决方案9】:

              您只需要下载最新版本的 chrome 和 chromedriver 并安装 它

              【讨论】:

                猜你喜欢
                • 2019-10-06
                • 2021-07-18
                • 2021-04-02
                • 1970-01-01
                • 1970-01-01
                • 2016-09-19
                • 2018-02-10
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多