AI 寫的打開 firefox 後再關閉
import tkinter as tk from selenium import webdriver from selenium.webdriver.firefox.service import Service from selenium.webdriver.firefox.options import Options import threading import time import psutil # 設置 Firefox 選項 options = Options() options . headless = False # 若需無頭模式,設置為 True options . binary_location = 'C: \\ Program Files \\ Mozilla Firefox \\ firefox.exe' # 指定 Firefox 的路徑 # 指定 GeckoDriver 的路徑 gecko_service = Service( 'D: \\ geckodriver.exe' ) # 初始化 driver driver = None def open_firefox (): global driver # 啟動瀏覽器 driver = webdriver . Firefox(service = gecko_service, options = options) # 打開指定的 URL driver . get( 'http://192.168.1.100' ) # 啟動監控線程 monitor_thread = threading . Thread(target = monitor_firefox, daemon = True ) monitor_thread . start() # 等待一段時間後關閉 Firefox time . sleep( 1 ) # 例如等待 10 秒 driver . quit() def monitor_firefox (): global driver ...