python-3.x - selenium.common.exceptions.WebDriverException:消息:无法找到 firefox 二进制文件。您可以通过指定“firefox_binary”的路径来设置它
问题描述
我想知道如何使用硒。抓取动态页面。与安装 Firefox 有什么关系吗?
from selenium import webdriver
driver=webdriver.Firefox()
selenium.common.exceptions.WebDriverException: Message: Failed to find firefox binary. You can set it by specifying the path to 'firefox_binary':
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/path/to/binary')
driver = webdriver.Firefox(firefox_binary=binary)
解决方案
此错误消息...
selenium.common.exceptions.WebDriverException: Message: Failed to find firefox binary. You can set it by specifying the path to 'firefox_binary':
...暗示GeckoDriver无法找到firefox二进制文件。
可能Firefox浏览器安装在您机器上的非常规位置,因此GeckoDriver无法找到它。
解决方案
如果Firefox安装在您机器上的非常规位置,您需要传递 Firefox 二进制文件的绝对位置,如下所示:
from selenium import webdriver
binary = '/path/to/firefox'
# Example of using Firefox Developer Edition on Windows OS
# binary = r'C:\Program Files\Firefox Developer Edition\firefox.exe'
# Example of using Firefox Nightly Edition on Windows OS
# binary = r'C:\Program Files\Nightly\firefox.exe'
options = webdriver.FirefoxOptions()
options.binary = binary
browser = webdriver.Firefox(firefox_options=options, executable_path='/path/to/geckodriver')
browser.get('http://google.com/')
browser.quit()
您可以在How to open Firefox Developer Edition through Selenium中找到相关讨论
推荐阅读
- android - Flutter - 如何从静态列表中进行动态下拉?
- macos - 在 MacOS 中使用 SYCL 1.2
- html - 如何在 django 上添加个人资料图片
- c++ - WSAConnectByName 替代手动分配缓冲区?
- c# - (422) 带有 ServiceStack 路由的不可处理实体
- active-directory - 如何为远程桌面注销延迟时间设置 AD 计算机组策略?
- javascript - 获取第一个和第二个逗号之间的文本字符串
- powershell - 使用 CSV 中的 PowerShell 更新 Sharepoint 在线列表
- javascript - 如何通过映射名称与来自另一个对象的特定 ID 来扩展对象?
- ios - 我应该在哪里定义 iOS 中 VIPER 架构中的业务逻辑,Swift