如何在Raspbian Buster上使用无头Firefox设置Selenium

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

[我已经将其与以前的Firefox版本一起在Jessie / Stretch中使用,但似乎无法使其与运行Raspbian Buster的Raspberry Pi 3B或4和最新的Selenium,Python中的3.141.0一起使用。

由于iceweasel不再可用,我通过apt安装firefox-esr并从https://github.com/mozilla/geckodriver/releases获取最新的ARM geckodriver,当前为0.23.0,然后运行以下代码:

from selenium import webdriver
from pyvirtualdisplay import Display
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = False
driver = webdriver.Firefox(options=options, executable_path='/usr/bin/geckodriver', capabilities=capabilities)
driver.get('https://www.google.com')
print(driver.page_source)
driver.close()
display.stop()

这将返回错误:

Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpxMUUcF If you specified a log_file in the FirefoxBinary constructor, check it for details.

Traceback (most recent call last):
  File "SeleniumDebugExample.py", line 50, in <module>
    driver = webdriver.Firefox(options=options, executable_path='/srv/main/geckodriver', capabilities=capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 191, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 73, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 114, in _wait_until_connectable
    % (self.profile.path))
WebDriverException: Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpxMUUcF If you specified a log_file in the FirefoxBinary constructor, check it for details.

尽管我正在指定geckodriver,所以我不确定问题是什么...

如果有人获得了无头的硒来研究Raspbian Buster,并且可以分享一些,将不胜感激!

python selenium raspberry-pi geckodriver debian-buster
1个回答
1
投票

经过一堆测试之后,问题似乎在于添加了marrionette = False功能...回到icesweasel的Jessie中,我需要对其进行添加才能使其正常工作,但似乎不再需要使用firefox-esr。 ..我可以通过以下方法使它起作用:

from selenium import webdriver
from pyvirtualdisplay import Display

driver = webdriver.Firefox(executable_path='/usr/bin/geckodriver')
driver.get('https://www.google.com')
print(driver.page_source)
driver.close()
display.stop()
© www.soinside.com 2019 - 2024. All rights reserved.