我的目的是自动化开google首页,然后关掉
这样的动作重复三次
而且原始程式码和错误讯息都有问过ChatGPT
但竟然遇到他无法替我解决...
程式只执行第一次,第二次就失败了...找不到原因QQ
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
# 创建 Chrome 浏览器实例
driver = webdriver.Chrome()
# 打开 Google 首页并关闭,重复三次
for i in range(3):
driver.get("https://www.google.com")
time.sleep(2) # 等待 2 秒
driver.quit() # 关闭当前浏览器窗口
time.sleep(5) # 等待 1 秒
# 退出程序
driver.quit()
错误讯息(只撷取部分):
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost',
port=54349): Max retries exceeded with url:
/session/582482805f77d9013496e6f4f969166f/url (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x0000016E5E8FE8B0>: Failed to establish a new connection: [WinError 10061] 无
法连线,因为目标电脑拒绝连线。'))
请问怎么解呢?
要怎么写才能让程式自动执行3次阿阿阿阿阿~~~QAQ