selenium.common.exceptions.WebDriverException:消息:找不到firefox二进制文件。你可以通过指定'firefox_binary'的路径来设置它

问题描述 投票:1回答:1

我想知道如何使用硒。刮动态页面。安装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)
python-3.x selenium firefox geckodriver selenium-firefoxdriver
1个回答
0
投票

此错误消息...

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无法找到它。


Incase 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找到相关的讨论

© www.soinside.com 2019 - 2024. All rights reserved.