如何修复 WebDriverException:浏览器似乎在我们可以连接之前已经退出? [英] How to fix WebDriverException: The browser appears to have exited before we could connect?

查看:73
本文介绍了如何修复 WebDriverException:浏览器似乎在我们可以连接之前已经退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Linux 系统中,我使用 Firefox,执行我的程序,我遇到的错误是:

In my Linux system I use Firefox, execute my program, the error which I've is:

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 执行我的程序就可以了.

If I use root execute my program is OK.

推荐答案

这是因为您没有正确设置以在没有 GUI 的情况下运行 Firefox.这是一个可能有用的教程Ubuntu 中的 Selenium Headless 自动化测试

This is because you did not set up correctly to run Firefox without GUI. This is a tutorial that might be helpful Selenium Headless Automated Testing in Ubuntu

我认为原因是您需要指定端口号,可能 xvfb 在与 Firefox 不同的端口上运行在一个终端上:
xvfb :99 -ac
在另一个终端上:
导出显示=:99
并运行你的scrapy程序不用root也能成功

I think the reason is you need to specify the port number, probably xvfb runs on a different port than Firefox on one terminal:
xvfb :99 -ac
on the another terminal:
export DISPLAY=:99
and run your scrapy program I am successful without using root

这篇关于如何修复 WebDriverException:浏览器似乎在我们可以连接之前已经退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆