在我的Linux系统中,我使用Firefox,执行我的程序,我所犯的错误是:
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 :(得分:10)
这是因为您没有正确设置以在没有GUI的情况下运行Firefox。 这是一个可能有用的教程 Selenium Headless Automated Testing in Ubuntu
我认为原因是您需要指定端口号,可能xvfb运行在与Firefox不同的端口上
在一个终端上:
xvfb :99 -ac
在另一个终端上:
export DISPLAY=:99
并运行你的scrapy程序
我没有使用root