【PYTHON】Selenium跨机控制Chrome窗口置顶方案 这里主要讲的是服务端和客户端分离场景【PYTHON】使用Selenium ChromeDriver执行操作时浏览器置顶B电脑运行Chrome的远端机器简易HTTP服务B电脑操作A电脑Selenium脚本机器B电脑运行Chrome的远端机器简易HTTP服务B机器安装依赖pipinstallpywin32 flaskwindow_service.pyB电脑运行fromflaskimportFlaskimportwin32guiimportwin32con appFlask(__name__)defbring_chrome_foreground():把Chrome窗口提升到前台并且最大化全屏wins[]defenum_callback(hwnd,result_list):titlewin32gui.GetWindowText(hwnd)ifChromeintitle:result_list.append((hwnd,title))win32gui.EnumWindows(enum_callback,wins)forhwnd,titleinwins:# SW_SHOWMAXIMIZED 3直接最大化窗口最小化状态也会直接弹起最大化win32gui.ShowWindow(hwnd,win32con.SW_SHOWMAXIMIZED)win32gui.SetForegroundWindow(hwnd)returnlen(wins)app.route(/bring_chrome_top,methods[GET])defapi_bring_top():countbring_chrome_foreground()return{code:0,msg:ok,chrome_window_count:count}if__name____main__:app.run(host0.0.0.0,port5000,debugFalse)B电脑操作运行python window_service.py防火墙放行5000端口否则A机器访问不通记下B电脑的局域网IP例如192.168.1.100A电脑Selenium脚本机器A机器连接remote chrome成功后发GET请求调用B的接口。importrequestsfromselenium.webdriver.remote.webdriverimportWebDriverfromselenium.webdriver.support.uiimportWebDriverWait# 远端B机器ipB_HOST192.168.1.100B_PORT5000defnotify_bring_chrome_top():A机器发http指令让B本机把Chrome置顶urlfhttp://{B_HOST}:{B_PORT}/bring_chrome_toptry:resprequests.get(url,timeout3)print(通知B机器置顶结果:,resp.json())exceptExceptionase:print(通知B置顶失败:,e)# 业务流程driver:WebDriverconnect_chrome()# 连接B电脑remote‑chromenotify_bring_chrome_top()# 调用B的http接口B本地执行窗口置顶waitWebDriverWait(driver,10)driver.get(https://xxxx)

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/10/6 14:10:51
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/10/6 12:50:27
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/10/5 19:39:38
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/10/5 16:06:34
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/10/6 12:44:38
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/10/6 12:38:14

日新闻

周新闻

月新闻