【问题标题】:socket.error: [Errno 54] Connection reset by peer Selenium-pythonsocket.error:[Errno 54] 对等 Selenium-python 重置连接
【发布时间】:2016-10-07 17:29:10
【问题描述】:

我是 selenium 的新手,正在尝试一个示例 http://www.marinamele.com/selenium-tutorial-web-scraping-with-selenium-and-python">这里

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException


def init_driver():
    driver = webdriver.Firefox()
    driver.wait = WebDriverWait(driver, 5)
    return driver


def lookup(driver, query):
    driver.get("http://www.google.com")
    try:
        box = driver.wait.until(EC.presence_of_element_located(
            (By.NAME, "q")))
        button = driver.wait.until(EC.element_to_be_clickable(
            (By.NAME, "btnK")))
        box.send_keys(query)
        button.click()
    except TimeoutException:
        print("Box or Button not found in google.com")


if __name__ == "__main__":
    driver = init_driver()
    lookup(driver, "Selenium")
    time.sleep(5)
    driver.quit()

我已经使用

安装了 selenium
pip install selenium

但它不起作用。

出现错误是

socket.error: [Errno 54] Connection reset by peer

有时

raise BadStatusLine(line)
httplib.BadStatusLine: ''

Firefox 打开然后关闭说“Firefox 已意外退出”

我经历了Selenium headless browser webdriver [Errno 104] Connection reset by peerWhy am I getting this error in python ? (httplib),但没有任何帮助。

【问题讨论】:

    标签: python sockets selenium


    【解决方案1】:

    降级您的 Firefox 并重试。看起来所有版本的 Firefox 都与 selenium 不兼容。

    参考:Selenium 2.50 not working on firefox 45

    【讨论】:

    • 有这方面的消息吗?我有 Selenium 2.53.1 和 firefox 47.0 。同样的错误
    【解决方案2】:

    这听起来很明显,但与现有答案相反,我想提醒您尝试升级您的 Selenium、Firefox 和 geckodriver 实例。

    我花了很多时间试图解决这个问题,然后才想起尝试一个简单的更新,它解决了这个问题。

    --

    在 Python 中使用

    更新 Selenium
    pip install --upgrade selenium
    

    检查 geckodriver 版本

    geckodriver --version
    

    安装最新的gecko driverFirefox

    【讨论】:

      猜你喜欢
      • 2016-03-03
      • 1970-01-01
      • 2019-12-07
      • 2020-07-10
      • 1970-01-01
      • 2014-01-01
      • 1970-01-01
      • 2017-04-12
      • 1970-01-01
      相关资源
      最近更新 更多