- 在微信小程序中拖动鼠标完成翻页功能,翻一页截一张图,并保存在本地。
import win32con, win32gui
from PIL import ImageGrab
import os
import time
import pyautogui
def get_window_pos(name):
name = name
handle = win32gui.FindWindow(0, name)
if handle == 0:
return None
else:
return win32gui.GetWindowRect(handle), handle
def cut_save(save_dir,target_nums):
(x1, y1, x2, y2), handle = get_window_pos('要截取的窗口的窗口标题')
win32gui.SendMessage(handle, win32con.WM_SYSCOMMAND, win32con.SC_RESTORE, 0)
win32gui.SetForegroundWindow(handle)
count = 1
while (count <= target_nums):
img_ready = ImageGrab.grab((x1, y1, x2, y2))
img_ready.save(os.path.join(save_dir, str(count) + '.png'))
count = count + 1
pyautogui.moveTo(1164, 625)
pyautogui.dragTo(760, 625, 0.5, button='left')
time.sleep(0.1)
if __name__ == '__main__':
cut_save(r'保存路径',截取数量)