Python ConnectionResetError:[WinError 10054]firefox上的selenium出现远程主机错误,已强制关闭现有连接

Python ConnectionResetError:[WinError 10054]firefox上的selenium出现远程主机错误,已强制关闭现有连接,python,selenium,selenium-webdriver,xpath,css-selectors,Python,Selenium,Selenium Webdriver,Xpath,Css Selectors,我得到了以下代码的错误 代码: import time from selenium import webdriver import urllib driver = webdriver.Firefox() driver.get('https://mycutebaby.in/contest/participant/?n=5b2b4bf83c352#_=_') voter = driver.find_element_by_id('verification_vote_btn') voter.click(

我得到了以下代码的错误

代码:

import time
from selenium import webdriver
import urllib
driver = webdriver.Firefox()
driver.get('https://mycutebaby.in/contest/participant/?n=5b2b4bf83c352#_=_')
voter = driver.find_element_by_id('verification_vote_btn')
voter.click()
Traceback (most recent call last):
  File "C:\Users\Hello\Documents\kritin_votes.py", line 5, in <module>
    driver.get('https://mycutebaby.in/contest/participant/?n=5b2b4bf83c352#_=_')
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 332, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 318, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 496, in _request
    resp = self._conn.getresponse()
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
错误:

import time
from selenium import webdriver
import urllib
driver = webdriver.Firefox()
driver.get('https://mycutebaby.in/contest/participant/?n=5b2b4bf83c352#_=_')
voter = driver.find_element_by_id('verification_vote_btn')
voter.click()
Traceback (most recent call last):
  File "C:\Users\Hello\Documents\kritin_votes.py", line 5, in <module>
    driver.get('https://mycutebaby.in/contest/participant/?n=5b2b4bf83c352#_=_')
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 332, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 318, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 496, in _request
    resp = self._conn.getresponse()
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 258, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 586, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
回溯(最近一次呼叫最后一次):
文件“C:\Users\Hello\Documents\kritin\u vows.py”,第5行,在
司机,上车https://mycutebaby.in/contest/participant/?n=5b2b4bf83c352#_=_')
文件“C:\Users\Hello\AppData\Local\Programs\Python36-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第332行,在get中
self.execute(Command.GET,{'url':url})
文件“C:\Users\Hello\AppData\Local\Programs\Python36-32\lib\site packages\selenium\webdriver\remote\webdriver.py”,第318行,在execute中
响应=self.command\u executor.execute(driver\u command,params)
文件“C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\site packages\selenium\webdriver\remote\remote\u connection.py”,第472行,执行
返回self.\u请求(命令信息[0],url,正文=数据)
文件“C:\Users\Hello\AppData\Local\Programs\Python36-32\lib\site packages\selenium\webdriver\remote\remote\u connection.py”,第496行,在请求中
resp=self.\u conn.getresponse()
文件“C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第1331行,在getresponse中
response.begin()
文件“C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\http\client.py”,第297行,在begin中
版本、状态、原因=self.\u读取\u状态()
文件“C:\Users\Hello\AppData\Local\Programs\Python36-32\lib\http\client.py”,第258行,处于读取状态
line=str(self.fp.readline(_MAXLINE+1),“iso-8859-1”)
readinto中的文件“C:\Users\Hello\AppData\Local\Programs\Python\Python36-32\lib\socket.py”,第586行
返回自我。将袜子重新放入(b)

ConnectionResetError:[WinError 10054]远程主机已强制关闭现有连接
点击文本为的元素点击投票您需要诱导WebDriverWait以使所需元素可单击,并且您可以使用以下任一解决方案:

  • CSS\u选择器

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.verification_vote-btn.vote_fb_btn#verification_vote_btn span.text"))).click()
    
  • XPATH

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='verification_vote-btn vote_fb_btn' and @id='verification_vote_btn']//span[contains(.,'Tap To Vote !')]"))).click()
    

“被远程主机强行关闭”让我觉得您试图编写一个脚本来尝试在一个网站上进行多次投票,它检测到您已经投票一次并断开连接。