Python自动重启中国移动光猫(ZXHN G7611V2)

广告位招租!

知识无价,人有情,无偿分享知识,希望本条信息对你有用!

本工具基于Python3.10,实现以无痕模式启动Chome浏览器,登录并重启中国移动光猫:

光猫型号:ZXHN G7611V2

配置环境可能需要用的代码

python 复制代码
pip3.10 install selenium
pip install selenium

需要下载并配置Chrome的webdriver

恭祝各位使用愉快!

完整可运行的Python代码

python 复制代码
import requests
from requests.auth import HTTPBasicAuth
import os
import webbrowser
from bs4 import BeautifulSoup
import re


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


# 指定 ChromeDriver 的路径
service = Service(r'C:\Users\David\Desktop\Reboot_Modem\chromedriver-win64\chromedriver.exe')

# 创建Chrome选项对象
chrome_options = Options()

# 添加无痕模式参数
chrome_options.add_argument("--incognito")

# 初始化 Chrome WebDriver
driver = webdriver.Chrome(service=service, options=chrome_options)

# 打开网页
driver.get("http://192.168.1.1")

ModemUser = "user" # 替换为你的用户名
ModemPassWord = "UserPassword" # 替换为你的密码


# 等待页面加载完成(可选)
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)

iframe = driver.find_element(By.ID, 'mainFrame')
#iframe=wait.until(EC.presence_of_element_located((By.NAME, '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()
相关推荐
xurileidian9 小时前
第 24 篇 · 边玩边学Python · while 与死循环怎么退
服务器·前端·python
有个傻瓜9 小时前
工具调用参数每次都差一截:finish_reason=length 输出预算截断的排错复盘与四种分诊实测
python·故障排查·ai agent·大模型应用开发·function calling
zhanghongyi_cpp10 小时前
第5章 学习自测
python·学习
打工仔折腾 AI11 小时前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
IvanCodes11 小时前
LangChain(15):LangSmith 应用评估与回归测试
python·langchain·agent
炸薯条!12 小时前
Python基础学习:文件操作详解(打开、读取、写入与路径)
java·服务器·python
jason_renyu14 小时前
Playwright 入门与实操:从安装、定位、断言到自动发博客,把浏览器自动化讲明白
运维·python·自动化·前端开发·浏览器自动化·playwright·e2e测试
维克兜率天14 小时前
【维克】布林带:通道类指标的“量化基石“
人工智能·python·算法
向科→向总工→空间动态计系统14 小时前
机器人大脑系统
开发语言·人工智能·python·机器人
染指111014 小时前
194.DeepAgents-在DeepAgents中使用自定义沙盒环境OpenSandBox
网络·人工智能·python·langchain·deepagents