【发布时间】:2018-02-15 00:07:22
【问题描述】:
我正在尝试使用 geckodriver 运行 webdriver。我已经安装了 selenium gecko、firefox 和 python27。我的文件夹有脚本和 geckodriver。
当我从 centOS 运行命令 python script.py 时,它会说
selenium.common.exceptions.WebDriverException: Message: Failed to start browser: permission denied
下面是我正在使用的脚本:
#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/usr/local/firefox')
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox(firefox_binary=binary)
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()
在你问之前,当我运行whereis firefox 时,我得到firefox: /usr/local/bin/firefox /usr/local/firefox
编辑:
在我运行sudo yum -y install firefox Xvfb libXfont Xorg 后,python scipt 启动,但我在 geckdriverlog 上收到错误消息:
XPCOMGlueLoad error for file /usr/local/firefox/libxul.so:
libdbus-glib-1.so.2: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
我认为这是由于this 错误。因此我尝试了sudo yum install libdbus-glib-1-2,但它说,No package libdbus-glib-1-2 available.
编辑 2:
所以也许我应该问(这可能是问题的答案);
如何在 CentOS 上使用终端安装 libdbus-glib-1-2 从 here 获取库?
编辑 3:
所以基本上要运行无头 Firefox,我需要 Xvfb,但是当我运行它 Xvfb :19 -screen 0 1024x768x16 & 时,我会卡在 Initializing built-in extension GLX 上,就像 this 问题一样。所以我认为问题归结为如何在 Xvfb 上运行无头 Firefox。
最后我要补充一点,Firefox 版本的东西就是一团糟。
【问题讨论】:
-
你在 mac 上吗?
-
没有在 CentOS 上
-
只有在无头运行时才会出现错误?或者错误也很严重。
-
我不能乱跑,因为它只是一个 aws 服务器。
-
我真的不知道如何处理赏金,因为它在 13 小时结束,我仍然没有得到正确的答案。
标签: amazon-web-services selenium selenium-webdriver centos gecko