Selenium Firefox无头运行问题在python中

时间:2016-02-09 04:48:28

标签: python firefox selenium httplib

我的python脚本出现此错误。我试图无头地使用selenium firefox。请问任何解决方案?

Traceback (most recent call last):
  File "myextractor.py", line 297, in <module>
    testweb_myextractor.Run()
  File "myextractor.py", line 80, in Run
    self.driver.get(self.link_to_explore)
  File "/home/dev/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 213, in get
    self.execute(Command.GET, {'url': url})
  File "/home/dev/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 199, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/home/dev/.local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
    return self._request(command_info[0], url, body=data)
  File "/home/dev/.local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 425, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1048, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1088, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 1044, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 888, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 850, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 831, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 575, in create_connection
    raise err
socket.error: [Errno 111] Connection refused

2 个答案:

答案 0 :(得分:0)

看起来你的webdraver与浏览器不兼容。

下载最新的Selenium WebDriver版本和Firefox ESR。它的稳定版本的mozilla没有更新。

https://www.mozilla.org/en-US/firefox/organizations/faq/

它现在和未来的帮助;)

答案 1 :(得分:0)

<强>要求:

  1. 每晚安装 Firefox
  2. 下载最新 geckodriver.exe &amp;把它放在PATH
  3. from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

    from selenium import webdriver

    //point to the location of firefox nightly binary = FirefoxBinary('C:\\Program Files\\Nightly\\firefox.exe', log_file=sys.stdout)

    driver = webdriver.Firefox(firefox_binary=binary)

    更多信息:https://intoli.com/blog/running-selenium-with-headless-firefox/