컴퓨터/Python

python kakao 친구목록

풍경소리^^ 2021. 2. 21. 23:10
import subprocess
import pyautogui
import time
from myid import PW
import pyperclip
import win32gui
import win32api
import win32con
import pyperclip
KakaoTalk="C:\Program Files (x86)\Kakao\KakaoTalk\KakaoTalk.exe"
k=subprocess.Popen(KakaoTalk)
#--------------------------------------------------------------------------------------
# hwnd = win32gui.FindWindow(None,"카카오톡")
# def SendReturn(hwnd):
#     win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
#     time.sleep(0.01)
#     win32api.PostMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
#======================================================================================
while True:
    lock_icon = pyautogui.locateOnScreen('login.png')
    if lock_icon != None:
        break
#--------------------------------------------------------------------------------------
# while True:
#     if hwnd !=None:
#         break
# win32api.SendMessage(hwnd, win32con.WM_SETTEXT, 0, PW)
# SendReturn(hwnd)
#======================================================================================
pyautogui.typewrite(PW)
pyautogui.press('enter')
time.sleep(1)
# 친구 목록
# 초기화
# tab
pyautogui.press('tab')
for i in range(0,5):
    pyautogui.press('down')
    # time.sleep(1)
# 친구 목록 초기화
friend2 = []
friend_type2 = []
tmp2 = []
friend_total_count = 10
pyperclip.copy('')
for i in range(0,friend_total_count):
    pyautogui.press('down')
    pyautogui.press('space')
    time.sleep(1)
    for j in range(0,5):
        pyautogui.hotkey('Shift','tab')
    time.sleep(1)
    pyautogui.press('space')
    # time.sleep(1)
    pyautogui.hotkey('ctrl', 'a')
    # time.sleep(1)
    pyautogui.hotkey('ctrl', 'c')
    txt = pyperclip.paste()
    # print(type(txt))
    # print(len(txt))
    if type(txt) != str or len(txt) == 0 or len(txt) >= 10:
#         # print("*시작",txt,"끝*")
        pyautogui.press('esc')
        pyautogui.hotkey('Shift', 'tab')
        # time.sleep(1)
        pyautogui.press('space')
        time.sleep(1)
        pyautogui.hotkey('ctrl', 'a')
        # time.sleep(1)
        pyautogui.hotkey('ctrl', 'c')
        txt = pyperclip.paste()
        if type(txt) != str or len(txt) == 0 or len(txt) >= 10:
    #         # print("*시작",txt,"끝*")
            pyautogui.press('esc')
            pyautogui.hotkey('Shift', 'tab')
            # time.sleep(1)
            pyautogui.press('space')
            time.sleep(1)
            pyautogui.hotkey('ctrl', 'a')
            # time.sleep(1)
            pyautogui.hotkey('ctrl', 'c')
            txt = pyperclip.paste()
        # print("if문 ",txt)
        # print(str(txt))
        # txt = pyperclip.paste()
    friend2.append(txt)
    friend_type2.append(type(txt))
    # time.sleep(1)
    pyautogui.press('esc')
    # time.sleep(1)
    pyautogui.press('esc')
    # time.sleep(1)
    pyperclip.copy('')
print(friend2)

'컴퓨터 > Python' 카테고리의 다른 글

class class 연동  (0) 2021.05.17
python pandas sns.histplot count  (0) 2021.03.29
selenium element 접근하기  (0) 2021.02.14
selenium 팝업창 모두 닫기  (0) 2021.02.14
win32gui 전체화면 캡쳐 창 캡쳐  (0) 2021.02.03