基本上写好所有的代码以后,运行,都会出现如下错误:刚刚打开这个慕课网的页面,就自动关闭了,比如这个代码
这是代码
#coding=utf-8
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome()
driver.get(“https://www.imooc.com/user/newlogin/from_url”)
driver.find_element_by_name(‘email’).send_keys("415232110@qq.com")
driver.find_element_by_name(“password”).send_keys(“hlpt757”)
driver.find_element_by_class_name(‘moco-btn’).click()
time.sleep(2)
driver.get(“https://www.imooc.com/user/setbindsns”)
driver.find_elements_by_class_name(‘inner-i-box’)[1].find_element_by_class_name(‘moco-btn-normal’).click()
handle_list = driver.window_handles
current_handle = driver.current_window_handle
print(handle_list)
time.sleep(15)
for i in handle_list:
if i != current_handle:
time.sleep(2)
driver.switch_to.window(i)
ti = EC.title_contains(“网站连接”)
if ti(driver) == True:
break
time.sleep(25)
driver.find_element_by_id(“userId”).send_keys(‘test’)
time.sleep(25)
driver.close()
这是错误
Traceback (most recent call last):
File “F:/Lessons/test/py/open_browser.py”, line 83, in
(selenium_driver.open_url_is_true(“http://www.imooc.com”,“程序员”))
File “F:/Lessons/test/py/open_browser.py”, line 64, in open_url_is_true
return self.assert_title(title_name)
File “F:/Lessons/test/py/open_browser.py”, line 60, in assert_title
return get_title(self.driver)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\support\expected_conditions.py”, line 51, in call
return self.title in driver.title
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 342, in title
resp = self.execute(Command.GET_TITLE)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 319, in execute
response = self.command_executor.execute(driver_command, params)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 374, in execute
return self._request(command_info[0], url, body=data)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 397, in _request
resp = self._conn.request(method, url, body=body, headers=headers)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\request.py”, line 75, in request
return self.request_encode_url(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\request.py”, line 97, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\poolmanager.py”, line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 747, in urlopen
return self.urlopen(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 747, in urlopen
return self.urlopen(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 747, in urlopen
return self.urlopen(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\connectionpool.py”, line 719, in urlopen
retries = retries.increment(
File “E:\Program Files (x86)\Python3.8\lib\site-packages\urllib3\util\retry.py”, line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=65510): Max retries exceeded with url: /session/5e13431257750094914b7666ef6e96af/title (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x000000B27BC98430>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。’))
Process finished with exit code 1
网上查了把浏览器代理设置为自动检测设置,但是这个方法并不管用,请教还有哪里有问题