python - 无法使用 Python 和 geckodriver 在 Raspbian 下运行 selenium-webdriver
问题描述
我试图让 selenium 在树莓派上以无头模式运行。我的脚本在我的 Windows 机器上运行良好,但我无法让这个特定的组合正常工作:
- Raspbian GNU/Linux 9(延伸)
- Python 3.7.3
- geckodriver 0.23.0 ( 2018-10-04)
- selenium-server-standalone-3.141.59
- 火狐浏览器 52.9.0
首先我按照文档selenium-server-standalone
中的描述启动:
$ java -jar selenium-server-standalone-3.141.59.jar &
[1] 1842
14:39:26.881 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
14:39:27.321 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-06-30 14:39:27.589:INFO::main: Logging initialized @2114ms to org.seleniumhq.jetty9.util.log.StdErrLog
14:39:28.755 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
14:39:29.174 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
然后我在 Python 中运行以下测试脚本:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 800))
display.start()
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get("http://google.com/")
driver.quit()
我收到以下错误消息:
Traceback (most recent call last):
File "debug3.py", line 10, in <module>
driver = webdriver.Firefox(options=options)
File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/opt/python37/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/opt/python37/lib/python3.7/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
解决方案
推荐阅读
- virtualbox - Virtual Box VT-x 不可用 (VERR_VMX_NO_VMX).. Hyper V 和核心隔离被禁用
- swiftui - 如何在 SwiftUI 中创建透明矩形
- mysql - 插入行 ER_TRUNCATED_WRONG_VALUE 出错:截断不正确的 DOUBLE 值:'null'
- python - 有没有办法改变 seaborn violin_plot 的颜色
- javascript - 为什么我会收到“很抱歉,如果没有启用 JavaScript,book_management_front 将无法正常工作。请启用它以继续”?
- r - Calling user defined function from data.table object
- oauth-2.0 - 为什么 Apereo CAS 服务器重定向到 OAuth2 端点的 localhost?
- java - Mockito 错误地注入字符串值
- python - ndarray 抛出数据必须是一维的
- html - 在 Microsoft Edge 中切换链接时出现奇怪的大纲行为