socket.error:[Errno 54]由对等Selenium-python重置连接

时间:2016-06-07 17:29:22

标签: python sockets selenium

我是selenium的新手,并尝试了一个示例http://www.marinamele.com/selenium-tutorial-web-scraping-with-selenium-and-python“> here

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)但没有任何帮助。

2 个答案:

答案 0 :(得分:2)

降级你的firefox并再试一次。看起来像所有版本的firefox都与selenium不兼容。

参考:Selenium 2.50 not working on firefox 45

答案 1 :(得分:0)

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

我花了很多时间尝试解决此问题,然后才记得尝试进行一次简单的更新即可解决问题。

-

使用Python更新Selenium

pip install --upgrade selenium

检查geckodriver版本

geckodriver --version

安装最新的gecko driverFirefox