python - 套接字错误 : [Errno 54] Connection reset by peer Selenium-python

标签 python sockets selenium

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

最佳答案

降级你的 firefox 并重试。看起来所有版本的 firefox 都不兼容 selenium。

引用:Selenium 2.50 not working on firefox 45

关于python - 套接字错误 : [Errno 54] Connection reset by peer Selenium-python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37685675/

相关文章:

python - 迭代列表并将该值用作字典键

c++ - "Destination address required"尝试通过 SOCK_RAW 套接字发送数据时

java - 如何获取输入元素的文本属性? - 网络驱动程序

c - INADDR_ANY 接口(interface)是否包括 VMware Network Adapter?

python - (Ubuntu) Python3 脚本运行良好,但在 Apache/wsgi 下找不到 selenium 模块

selenium - 使用 selenium 进行身份验证 (Python)

python - 如何使用理解来减少字典值中的集合?

python - 文件太大无法读取

python - 如何在 Python WebDriver 中等待 CSS 和 XPath 选择器的组合?

c - 数据类型 - socklen_t、sa_family_t