编辑:这似乎不是重复的,因为链接的帖子答案中的任何建议都没有修复错误。这是运行脚本后的 geckodriver.log:
1538960169585 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile.xicOi27i6laa"
1538960178656 Marionette INFO Listening on port 2828
^G[Child 17792] ###!!! ABORT: Aborting on channel error.: file /build/firefox-esr-YKrXxr/firefox-esr-52.9.0esr/ipc/glue/MessageChannel.cpp, line 2152
[Child 17792] ###!!! ABORT: Aborting on channel error.: file /build/firefox-esr-YKrXxr/firefox-esr-52.9.0esr/ipc/glue/MessageChannel.cpp, line 2152
我无法在无头 Raspberry Pi 3 B+ 上创建运行 python 3.5 的 webdriver 实例。我跑了
sudo apt-get install python-pip iceweasel xvfb
pip install pyvirtualdisplay selenium
安装依赖项。但是,当我运行基本脚本来创建 selenium WebDriver 时,我会收到一条WebDriverException: Message: connection refused
消息。
我的代码:
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
profile = webdriver.FirefoxProfile()
profile.native_events_enabled = False
driver = webdriver.Firefox(profile)
错误信息:
Traceback (most recent call last):
File "simpletest", line 10, in <module>
driver = webdriver.Firefox(firefox_profile=profile)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/pi/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused
这个来自另一个论坛的答案表明上面的代码应该可以工作。任何帮助表示赞赏。