Windows下使用Python Selenium遇'binary is not a Firefox executable'错误求助
问题解决
你的代码中options.binary_location的赋值方式存在错误,多写了executable_path=关键字,正确的写法是直接将Firefox可执行文件的路径字符串赋值给binary_location。
修正后的代码如下:
from selenium import webdriver from selenium.webdriver.firefox.service import Service from selenium.webdriver.firefox.options import Options driver_service = Service(executable_path=r"C:\Program Files (x86)\geckodriver.exe") options = Options() # 移除多余的executable_path=,直接赋值路径字符串 options.binary_location = r"C:\Program Files\Mozilla Firefox\firefox.exe" driver = webdriver.Firefox(service=driver_service, options=options) driver.get("https://google.com")
额外检查项:
- 再次确认路径指向的是真实的
firefox.exe文件,而非快捷方式 - 确保运行代码的用户对该文件路径拥有读取权限
内容的提问来源于stack exchange,提问作者melian27
相关产品推荐
相关产品推荐

