广告位招租知识无价人有情无偿分享知识希望本条信息对你有用本工具基于以下博文代码修改所得Python自动重启中国移动光猫ZXHN G7611V2https://blog.csdn.net/ncutyb123/article/details/163782841?spm1001.2014.3001.5501Python自动重启中国移动子光猫 ZXHN G1612https://blog.csdn.net/ncutyb123/article/details/163870922?spm1001.2014.3001.5501本工具基于Python3.10实现以无痕模式启动Chome浏览器登录并重启中国移动光猫主网关型号ZXHN G7611V2子网关型号ZXHN G1612import requests from requests.auth import HTTPBasicAuth import os import webbrowser from bs4 import BeautifulSoup import re import subprocess from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.chrome.service import Service from selenium.webdriver import ActionChains from selenium.webdriver.common.actions.action_builder import ActionBuilder from selenium.webdriver.common.actions.mouse_button import MouseButton # Reboot subgateway # 替换成你自己的文件路径 subprocess.run([python, rC:\Users\David\Desktop\Reboot_Modem\RebootSubGateway.py]) # 指定 ChromeDriver 的路径 service Service(rC:\Users\David\Desktop\Reboot_Modem\chromedriver-win64\chromedriver.exe) # 创建Chrome选项对象 chrome_options Options() # 添加无痕模式参数 chrome_options.add_argument(--incognito) # 初始化 Chrome WebDriver driver webdriver.Chrome(serviceservice, optionschrome_options) # 打开网页 driver.get(http://192.168.1.1) # 替换为你的密码 ModemUser user ModemPassWord YourPassWord # 等待页面加载完成可选 wait WebDriverWait(driver, 15) username wait.until(EC.presence_of_element_located((By.NAME, Username))) password driver.find_element(By.NAME, Password) username.send_keys(ModemUser) password.send_keys(ModemPassWord) password.send_keys(Keys.RETURN) # 提交表单 wait WebDriverWait(driver, 20) # 打开网页 driver.get(http://192.168.1.1/start.ghtml) wait WebDriverWait(driver, 15) # Reboot main gateway iframe driver.find_element(By.ID, mainFrame) driver.switch_to.frame(iframe) button driver.find_element(By.ID, mmManager) button.click() wait WebDriverWait(driver, 5) button driver.find_element(By.ID, smSysMgr) button.click() wait WebDriverWait(driver, 10) button driver.find_element(By.NAME, Submit1) button.click() button driver.find_element(By.ID, msgconfirmb) button.click() # 关闭浏览器 driver.quit()