Selenium gives “selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary” on Mac

前端 未结 6 2047
星月不相逢
星月不相逢 2020-12-06 04:29

Trying to get selenium to work with Python 3 for web scraping purposes:

from selenium import webdriver
chrome_path = r\"/Library/Frameworks/Pyth         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 05:33

    It is important on Win to set the name of chrome.exe otherwise it fail to create a process (see below):

      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: Message: unknown error: Failed to create a Chrome process.

    For Firefox (download driver 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)
    

提交回复
热议问题