我想知道如何使用硒。刮动态页面。安装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无法找到它。
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找到相关的讨论