2024年2月7日 星期三

pyautogui sample

 import pyautogui

import time

import pyperclip


# 打開瀏覽器(這裡以Chrome為例)

pyautogui.hotkey('winleft', 'r')

pyautogui.typewrite('chrome.exe')

pyautogui.press('enter')

time.sleep(1)  # 等待瀏覽器啟動

pyautogui.press('tab')

pyautogui.press('enter')

time.sleep(1)

# pyautogui.hotkey('ctrl', 't')


# 複製文本到剪貼板

pyperclip.copy('https://www.cyvs.cy.edu.tw/home')


# 從剪貼板粘貼

# copied_text = pyperclip.paste()


# 模擬按下 Ctrl+L(選中網址列)

pyautogui.hotkey('ctrl', 'l')

time.sleep(1)  # 等待一秒,確保網址列有足夠的時間被選中


# 模擬按下 Ctrl+V(貼上內容)

pyautogui.hotkey('ctrl', 'v')


# 模擬按下 Enter(確認貼上)

pyautogui.press('enter')


time.sleep(2)  # 等待網站載入


f_button1 = pyautogui.locateOnScreen('forstu.png')

if f_button1 is not None:

    pyautogui.click(f_button1.left + 5, f_button1.top + 5)

else:

    print("找不到按鈕")

沒有留言:

張貼留言