import pyautogui
import time
from PIL import Image
defcapture_screenshot(page_number):
screenshot = pyautogui.screenshot(region=(0,0,821,1090))# 定义截图区域,左上角x,y,右下角x,y
screenshot.save(f'wechat_chat_page_{page_number}.png')print(f'Captured chat page {page_number}')defscroll_chat():# Adjust the scrolling distance and speed as needed
pyautogui.scroll(+1000)# 偏移量,+是向上滚动,-是向下滚动
time.sleep(2)# 滚动间隔时间defis_end_of_chat():# Implement a method to detect if the current page is the last one# This is just a placeholder; you'll need to adjust it to your specific case# For example, you could compare the new screenshot with the previous one to check for changesreturnFalsedefmain():
page_number =1whileTrue:
capture_screenshot(page_number)if is_end_of_chat():break
scroll_chat()
page_number +=1print("Finished capturing all chat pages.")if __name__ =="__main__":
main()