如何在 Windows 上拦截 Toast 通知,从中复制文本,然后将其粘贴到所需位置?

问题描述 投票:0回答:1

我希望你一切都好。

我正在尝试创建一个登录某个网站的程序(自动化过程),该程序会提示 Duo Push(身份验证方法),将短信发送到我的手机。我需要复制此文本消息(在 Windows 10 上作为 Toast 通知提示(已附),然后将其粘贴到 Duo Push 文本空间中,然后单击验证按钮。虽然我知道如何在此过程中执行几乎所有操作,我正在努力寻找在 Windows 计算机上捕获 Windows Toast 通知、从中获取 SMS 代码,然后将其存储在剪贴板中(然后粘贴)的方法。

似乎Python中的每个库(我用来创建它的编程语言)都没有这个函数(例如win10toast)来拦截Windows toast通知,更不用说读取它了。如果有帮助的话,我正在使用 selenium 和 chrome Web 驱动程序来执行此 Web 进程。

如果您可以的话,请告诉我是否可以做到这一点,我将非常感激。

提前谢谢您!

python web notifications screen-scraping
1个回答
0
投票

我唯一的猜测是制作图像并使用 OCR(光学字符识别)来获取其中的文本。 这是一个例子:

import pyautogui
import easyocr

# Change your Region to capture the Toast Message
region = (100, 100, 500, 400)

# Take a screenshot of the specified region
screenshot = pyautogui.screenshot(region=region)

# Save the screenshot
screenshot.save("screenshot.png")

# Use OCR to extract the contents of the toast message
reader = easyocr.Reader(['en'])
result = reader.readtext("screenshot.png")

# Print or use the extracted message
for detection in result:
  print(detection[1])

可以用,但是有点慢

© www.soinside.com 2019 - 2024. All rights reserved.