我花了几个小时尝试让Python与Selenium配合使用,但是没有成功。出现了以下错误信息:selenium.common.exceptions.WebDriverException: Message: connection refused
。这是我使用的示例:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get('http://www.python.org')
browser.close()
这是我安装的依赖项:apt-get install -y xorg xvfb dbus-x11 xfonts-100dpi xfonts-75dpi xfonts-cyrillic
这是/root/geckodriver.log
的输出
1493938773101 geckodriver INFO 正在监听 127.0.0.1:40876 1493938774156 geckodriver::marionette INFO 正在启动浏览器 /usr/lib/firefox/firefox.sh,参数为 ["-marionette"] (firefox:3128): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed
我在一台128MB RAM的远程Ubuntu 14.04 64位VPS服务器上运行Selenium,但无法与Chrome和Firefox的驱动程序通信,我不知道哪里出了问题。