From c412fa1a803ec0bf980458e5a1a96db548d04f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E7=8B=BC=E8=93=9D=E5=A4=A9?= Date: Tue, 23 Jul 2024 14:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A9=B1=E5=8A=A8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run_window_v4.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/run_window_v4.py b/run_window_v4.py index 58910ab..cc61854 100644 --- a/run_window_v4.py +++ b/run_window_v4.py @@ -64,6 +64,23 @@ port = config.get('WebSocket', 'port') sio.connect("ws://"+host+":"+port) # WebDriver初始化 def init_webdriver(driver_type): + # 先检查是否配置了自行安装的驱动 + try: + if driver_type.lower() == "edge" and driver_path_edge: # 只有在Edge类型且路径已知的情况下才尝试使用已存在的驱动 + edge_options = Options() # 创建Edge的Options实例 + service = Service(executable_path=driver_path_edge) # 使用已知的驱动路径 + driver = webdriver.Edge(service=service, options=edge_options) # 传入Options实例 + logging.info("使用自行安装的Edge") + return driver + elif driver_path_chrome: + edge_options = Options() # 创建Edge的Options实例 + service = Service(executable_path=driver_path_chrome) # 使用已知的驱动路径 + driver = webdriver.Edge(service=service, options=edge_options) # 传入Options实例 + logging.info("使用自行安装的Chrome") + return driver + except Exception as e: + logging.info("使用本地驱动失败,请先配置本地驱动。"+e.args[0]) + options = Options() manager = { "firefox": GeckoDriverManager,