Python自动化:使用pyautogui实现图片点击和Excel操作
import pyautogui
import time
import openpyxl
# 打开Excel文件
workbook = openpyxl.load_workbook(r'C:\Users\Administrator\Desktop\照片查询.xlsx')
# 选择Sheet1工作表
sheet = workbook['Sheet1']
# 获取H列的所有单元格内容
column_h = sheet['H']
# 点击图片函数
def click_image(image_path):
location = pyautogui.locateOnScreen(image=image_path)
pyautogui.click(location)
time.sleep(1)
# 循环处理每一行数据
for cell in column_h:
# 复制学号到剪贴板
pyautogui.typewrite(cell.value)
# 点击图片4
click_image(r'C:\Users\Administrator\Desktop\4.png')
# 等待图片6出现
time.sleep(1)
if pyautogui.locateOnScreen(r'C:\Users\Administrator\Desktop\6.png'):
# 如果出现图片6,说明已经采集
print('已采集')
else:
# 如果没有出现图片6,说明未采集
print('未采集')
# 在R列对应的单元格中写入'未采集'
sheet.cell(row=cell.row, column=18).value = '未采集'
# 保存Excel文件
workbook.save(r'C:\Users\Administrator\Desktop\照片查询.xlsx')
# 点击图片5
click_image(r'C:\Users\Administrator\Desktop\5.png')
原文地址: https://www.cveoy.top/t/topic/ftTQ 著作权归作者所有。请勿转载和采集!