无法在服务器上的python中从selenium调用firefox

时间:2016-06-22 05:42:08

标签: python selenium firefox xvfb

我尝试在AWS机器上通过Python中的selenium调用firefox。

我查看之前的帖子(this onethis one)。 但是,他们的解决方案并不直接适用于我。 我使用了以下代码示例,但是出现了如下所述的错误。

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(1024, 768))
display.start()

driver= webdriver.Firefox()
driver.get("http://www.somewebsite.com/")

<---some code--->

#driver.close() # Close the current window.
driver.quit() # Quit the driver and close every associated window.
display.stop()

我收到以下错误:

> driver= webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 81, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 51, 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 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
    raise WebDriverException("The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. 
If you specified a log_file in the FirefoxBinary constructor, check it for details.

我安装了xvfb和pyvirtualdisplay而没有错误。 我的firefox是最新的。

如果我单独运行firefox,我也会遇到如下错误。

> firefox &
[2] 1436
> PuTTY X11 proxy: unable to connect to forwarded X server: Network error: Connection refused
[2]-  Exit 127

请随时分享您的想法。谢谢!

0 个答案:

没有答案