Skip to main content
 首页 » 编程设计

python之WebDriverException : Message: unknown error: no chrome binary at C:/. ../Chrome/Application/chrome.exe 与 ChromeDriver Selenium 和 Python

2024年12月31日24haluo1

这里有点像 Python 新手......

Windows 7 x64 和 Python 3.7

我已经安装了 Selenium 和 Chrome Webdriver。我正在使用:

from selenium import webdriver 
from selenium.webdriver.chrome.options import Options 
 
options = Options() 
options.binary_location = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe' 
driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe') 
driver.get('http://google.com/') 

我得到:

\python\python.exe C:/py/defectURLS/app.py 
C:/py/defectURLS/app.py:6: DeprecationWarning: use options instead of chrome_options 
  driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe') 
Traceback (most recent call last): 
  File "C:/py/defectURLS/app.py", line 6, in <module> 
    driver = webdriver.Chrome(chrome_options=options, executable_path='C:/python/chromedriver.exe') 
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\chrome\webdriver.py", line 81, in __init__ 
    desired_capabilities=desired_capabilities) 
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 157, in __init__ 
    self.start_session(capabilities, browser_profile) 
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 252, in start_session 
    response = self.execute(Command.NEW_SESSION, parameters) 
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\webdriver.py", line 321, in execute 
    self.error_handler.check_response(response) 
  File "C:\python\lib\site-packages\selenium-3.141.0-py3.7.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at C:/Program Files (x86)/Google/Chrome/Application/chrome.exe 
  (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64) 

现在,我很确定确凿的证据是:

 selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at C:/Program Files (x86)/Google/Chrome/Application/chrome.exe 
      (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 6.1.7601 SP1 x86_64) 

这向我表明,Selenium 可以找到 webdriver,因为它能够报告 webdriver 版本。该错误似乎表明 chrome 二进制文件未位于给定位置。但我完全确定这就是 Chrome.exe 所在的位置。我可以直接从该路径启动 chrome.exe,完全没有问题。

非常感谢指导可能出现的问题。

请您参考如下方法:

这个错误信息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally 

...暗示 ChromeDriver 无法找到 chrome 二进制文件 chrome.exe

您需要考虑以下几个事实:

  • 可能您正在使用 Selenium Python Client v3.14.1 或 Selenium Python Client v3.141.0 和 chrome_options现在已弃用。您需要使用 options 虽然chrome_options 仍然有效。
  • key executable_path必须由 Value 支持,如下所示:
    • r'C:\python\chromedriver.exe'
    • "C:/python/chromedriver.exe"
    • "C:\\python\\chromedriver.exe"