Selenium 提示由于目标计算机积极拒绝,无法连接。

代码如下:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

browser = webdriver.Chrome()

try:
    browser.get("https://www.baidu.com";)
    input = browser.find_element_by_id("kw")
    input.send_keys("Python")
    input.send_keys(Keys.ENTER)
    wait = WebDriverWait(browser, 10)
    wait.until(EC.presence_of_all_elements_located((By.ID, 'content_left')))
    print(browser.current_url)
    print(browser.get_cookies())
    print(browser.page_source)
finally:
    browser.close()


错误如下: C:\Users\Administrator\AppData\Local\Programs\Python\Python35\python.exe C:/Users/Administrator/PycharmProjects/spider/Selenium.py Traceback (most recent call last):   File "C:/Users/Administrator/PycharmProjects/spider/Selenium.py", line 10, in <module>     browser.get("https://www.baidu.com";)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in get     self.execute(Command.GET, {'url': url})   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 306, in execute     response = self.command_executor.execute(driver_command, params)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 464, in execute     return self._request(command_info[0], url, body=data)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 488, in _request     resp = self._conn.getresponse()   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1197, in getresponse     response.begin()   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 297, in begin     version, status, reason = self._read_status()   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 258, in _read_status     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\socket.py", line 575, in readinto     return self._sock.recv_into(b) ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接。 During handling of the above exception, another exception occurred: Traceback (most recent call last):   File "C:/Users/Administrator/PycharmProjects/spider/Selenium.py", line 20, in <module>     browser.close()   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 593, in close     self.execute(Command.CLOSE)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 306, in execute     response = self.command_executor.execute(driver_command, params)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 464, in execute     return self._request(command_info[0], url, body=data)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 487, in _request     self._conn.request(method, parsed_url.path, body, headers)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1106, in request     self._send_request(method, url, body, headers)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1151, in _send_request     self.endheaders(body)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1102, in endheaders     self._send_output(message_body)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 934, in _send_output     self.send(msg)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 877, in send     self.connect()   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 849, in connect     (self.host,self.port), self.timeout, self.source_address)   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\socket.py", line 711, in create_connection     raise err   File "C:\Users\Administrator\AppData\Local\Programs\Python\Python35\lib\socket.py", line 702, in create_connection     sock.connect(sa) ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。 进程已结束,退出代码1

要回复问题请先登录注册