2014-12-03 37 views
4

在我的Linux系统,我使用的是Firefox,执行我的计划,这是我去过的错误是:如何解决WebDriverException:在我们可以连接之前,浏览器似乎退出了?

Traceback (most recent call last): 

File "shenma_diff_main_v2.py", line 90, in <module> 
    browser = webdriver.Firefox(profile) 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__ 
    self.binary, timeout), 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__ 
    self.binary.launch_browser(self.profile) 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser 
    self._wait_until_connectable() 
    File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, 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. 

如果我用root执行我的计划是确定。

+0

看看我的答案在这里 2015-01-14 07:37:02

回答

9

这是因为您没有正确设置以在没有GUI的情况下运行Firefox。 这是一个可能会有所帮助的教程 Selenium Headless Automated Testing in Ubuntu

我想原因是你需要一个终端上指定的端口号,可能xvfb的运行不同的端口比Firefox 上:在另一个
xvfb :99 -ac
终端:
export DISPLAY=:99
和运行scrapy程序 我成功了,而无需使用根

+1

您的评论没有在链接的答案中提到,但这工作为了我! – 2015-12-04 14:48:33

+0

感谢您的参考很清楚... – Richard 2015-12-08 02:55:59

+0

也检查出http://stackoverflow.com/questions/13039530/unable-to-call-firefox-from-selenium-in-python-on-aws-machine – honi 2015-12-27 04:17:34

相关问题