Sometimes you need to monitor whether the information on the screen changes in real time. For example, monitoring whether a certain official account sends a push may be an important source of information for you. You want to pay attention to it as soon as possible. Go, grab hot spots, etc. Then you can use Python to write such a script to monitor changes in screen pixels. As long as the pixels change, it basically means that the content has changed.
Loop screenshots to monitor interface pixel changes. If the pixels change, the interface changes.
When the pixel changes, a notification will be POSTed to your notification URL. At this time, the client you receive the notification will send you a reminder.
import time import numpy as np import requests from PIL import ImageGrab # 指定要监测的区域 monitor_area = (0, 0, 100, 100) # (左上角x坐标, 左上角y坐标, 右下角x坐标, 右下角y坐标) # 初始截图 last_screen = np.array(ImageGrab.grab(monitor_area)) # 指定HTTP请求的URL url = "改成你的POST通知的URL,例如企业微信、Bark、钉钉、发送邮件等" while True: # 捕获当前屏幕截图 current_screen = np.array(ImageGrab.grab(monitor_area)) # 将上次截图和当前截图进行比较 difference = np.sum(np.abs(current_screen - last_screen)) if difference > 0: # 发送HTTP POST请求 data = {"timestamp": time.time(), "difference": difference} response = requests.post(url, data=data) print(response.text) # 更新上次截图 last_screen = current_screen # 休眠一段时间,然后继续循环 time.sleep(1)
I am using Bark for IOS and POST notifications directly to the APP:
This is more convenient As a way, you can also build your own email notification service, enterprise WeChat robot, DingTalk robot and other notification services to receive notifications.
The above is the detailed content of How to monitor screen interface content changes and send notifications in Python. For more information, please follow other related articles on the PHP Chinese website!