硒-http.client.RemoteDisconnected:远端关闭的连接,无响应

时间:2019-01-07 00:42:09

标签: python selenium selenium-chromedriver

我正在使用Selenium的ChromeDriver编写Python脚本,以从网站中获取一些数据。这是代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import random

#setup - don't change
driver = webdriver.Chrome('/Users/arnavchandra/Downloads/ChromeDriver/chromedriver')
driver.get('http://puzzlemaker.discoveryeducation.com/WordSearchSetupForm.asp')


#basic text fields
title = driver.find_element_by_name('TITLE')
title.send_keys('Arnav')
width = driver.find_element_by_name('WIDTH')
width.clear()
width.send_keys('40')
height = driver.find_element_by_name('HEIGHT')
height.clear()
height.send_keys('40')

#radio buttons
driver.find_element_by_css_selector("input[type='radio'][value='TEXT']").click()

#text area
words = driver.find_element_by_name('WORDS')
wordlist = []
file = open("words.txt", "r")
i = 1
while(i <= 119):
        word = file.readline()
        word = word.replace('\n', '')
        wordlist.append(word)
        i = i + 1

wordspicked = 0
while(wordspicked < 50):
        wordindex = random.randint(0, 119 - wordspicked - 1)
        words.send_keys(wordlist[wordindex])
        words.send_keys(' ')
        wordlist.remove(wordlist[wordindex])
        wordspicked = wordspicked + 1

#submit button
driver.find_element_by_css_selector("input[type='submit'][value='Create My Puzzle!']").click()

一切正常,直到最后一行按下“提交”按钮为止。这是发生这种情况时出现的错误:

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response 

我也明白了:

During handling of the above exception, another exception occurred:    
Traceback (most recent call last):
  File "form.py", line 43, in <module>
    driver.find_element_by_css_selector("input[type='submit'][value='Create My Puzzle!']").click()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 319, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 374, in execute
    return self._request(command_info[0], url, body=data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 397, in _request
    resp = self._conn.request(method, url, body=body, headers=headers)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/request.py", line 72, in request
    **urlopen_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/request.py", line 150, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/poolmanager.py", line 323, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/retry.py", line 367, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 384, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 380, in _make_request
    httplib_response = conn.getresponse()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) 

我查看了不同的答案,包括:http.client.RemoteDisconnected: Remote end closed connection without response 这是Selenium raise RemoteDisconnected: Remote end closed connection without response 但他们都没有回答我的问题

0 个答案:

没有答案