Python 自动化操作桌面小程序 - 打开 '我的照片查询' 和 '考试照片查询'
你可以使用 pyautogui 库来模拟鼠标点击和键盘操作,实现打开桌面小程序并点击其中的按钮。以下是一个示例代码:
import os
import pyautogui
import time
# 定义桌面快捷方式的路径
shortcut_path = "C:\\Users\\Administrator\\Desktop\\国开照片采集工具.lnk"
# 打开桌面快捷方式
os.startfile(shortcut_path)
# 等待小程序打开
time.sleep(3)
# 在打开的小程序中找到 '我的照片查询' 字样并点击打开
my_photos_button_location = pyautogui.locateOnScreen('my_photos_button.png')
if my_photos_button_location:
my_photos_button_center = pyautogui.center(my_photos_button_location)
pyautogui.click(my_photos_button_center)
# 等待页面加载
time.sleep(3)
# 在打开的小程序中找到 '考试照片查询' 字样并点击打开
exam_photos_button_location = pyautogui.locateOnScreen('exam_photos_button.png')
if exam_photos_button_location:
exam_photos_button_center = pyautogui.center(exam_photos_button_location)
pyautogui.click(exam_photos_button_center)
在上述代码中,你需要将 my_photos_button.png 和 exam_photos_button.png 替换为实际的按钮图片,请确保按钮图片与实际应用界面一致。你可以使用截图工具(如 Snipping Tool)来获取按钮的截图,然后保存为相应的图片文件。
原文地址: https://www.cveoy.top/t/topic/bsK3 著作权归作者所有。请勿转载和采集!