|
import pyautogui
import time
def capture_area(x1, y1, x2, y2,no):
"""根据坐标截图并保存"""
try:
# 确保坐标有效性
left = min(x1, x2)
top = min(y1, y2)
right = max(x1, x2)
bottom = max(y1, y2)
# 计算区域尺寸
width = right - left
height = bottom - top
# 截取屏幕区域
screenshot = pyautogui.screenshot(region=(left, top, width, height))
# 生成带时间戳的文件名
filename = f"{no}.png"
screenshot.save(filename)
print(f"截图成功!保存为:{filename}")
return filename
except Exception as e:
print(f"截图失败:{str(e)}")
return None
if __name__ == "__main__":
time.sleep(3)
no=1
while True:
capture_area(370, 150, 2200, 1450,no)
time.sleep(1)
pyautogui.click(2412,1284)
time.sleep(3)
no=no+1
|
|