def check_browser(): """ 检查是否已经打开了浏览器 """ try: options = Options() options.add_experimental_option("debuggerAddress", "127.0.0.1:9527") browser = webdriver.Chrome(options=options) browser.execute_script("return true;") return True except: return False

if name == 'main': if not check_browser(): os.system(r'start chrome --remote-debugging-port=9527 --user-data-dir="D:\评阅用"') options = Options() options.add_experimental_option("debuggerAddress", "127.0.0.1:9527") browser = webdriver.Chrome(options=options) browser.get('https://menhu.pt.ouchn.cn/site/ouchnPc/index') print(browser.title

import osfrom selenium import webdriverfrom seleniumwebdriverchromeoptions import Options#试用CMD命令打开一个新的浏览器if __name__ == __main__ if not check_browser ossystemrstart chrome --remote-debuggin

原文地址: https://www.cveoy.top/t/topic/g6jd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录