Firefox二进制文件错误'浏览器似乎已退出'

时间:2015-04-07 18:17:33

标签: python-2.7 firefox selenium selenium-webdriver xvfb

当我运行下面的代码时,我遇到了selenium和Firefox的问题:

    from selenium import webdriver
    from selenium.common.exceptions import TimeoutException
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from bs4 import BeautifulSoup
    import urllib2,cookielib
    import re
    from pyvirtualdisplay import Display
    import urllib
    import urllib2
    import httplib2
    from os import system

    display = Display(visible=0, size=(800, 600))
    display.start()

    name = 'test'
    driver = webdriver.Firefox()
    driver.get("http://example.com")
    driver.switch_to_default_content()
    inputElement = driver.find_element_by_name("name")
    inputElement.send_keys(name)
    inputElement.submit()
    print "Please wait for 5s to get results.."
    content = driver.page_source.encode("utf-8")
    html = str(content)
    soup = BeautifulSoup(html)
    print soup
    display.stop()
    driver.close()

我得到了这个错误:

    Exception in thread command9:
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/threading.py", line 551, in __bootstrap_inner
        self.run()
      File "/usr/local/lib/python2.7/threading.py", line 504, in run
        self.__target(*self.__args, **self.__kwargs)
      File "plugins/help_plugin.py", line 165, in handler_search
        search_number_ar(type, source, parameters)
      File "plugins/test.py", line 230, in search_test
        driver = webdriver.Firefox()
      File "/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
        self.binary, timeout),
      File "/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/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-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 66, in launch_browser
        self._wait_until_connectable()
      File "/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
        raise WebDriverException("The browser appears to have exited "
    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.

我的代码在vps中运行,我使用selenium-2.45.0firefox.x86_64-31.6.0。 我尝试了很多方法来解决我的问题,但没有任何与我合作的方法。 我尝试更新selenium,我尝试降级firefox和很多解决方案。

只是知道我第一次运行我的代码时它的工作情况,但是当我再次运行它时,它会向我显示上述错误。

我希望有人帮忙。

0 个答案:

没有答案