102 lines
4.0 KiB
Python
102 lines
4.0 KiB
Python
from pywinauto import Application, findwindows, timings
|
|
import time, pyperclip, os
|
|
|
|
|
|
# # 네이버 웨일을 시크릿 모드로 UID 방식으로 실행
|
|
# app = Application().start("C:\\Program Files\\Naver\\Naver Whale\\Application\\whale.exe --incognito")
|
|
# time.sleep(5) # 프로그램이 완전히 로드될 때까지 대기
|
|
|
|
|
|
url = 'https://file.percenty.co.kr/public/652bed8e865b1f32ea62bf1f/products/6734dc6f9acd55067354225d/0c0fbc92-e52a-4e8e-982e-036b224eb71a.jpg'
|
|
|
|
whale_exe_path = os.path.join(os.getcwd(), "browsers", "whale", "whale.exe")
|
|
user_data_dir = os.path.join(os.getcwd(), "browsers", "whale", "user_data")
|
|
cache_dir = os.path.join(os.getcwd(), "browsers", "whale", "cache")
|
|
|
|
whale_app = Application(backend="uia").start(
|
|
# f'"{whale_exe_path}" --incognito --user-data-dir="{user_data_dir}" --disk-cache-dir="{cache_dir}"'
|
|
f'"{whale_exe_path}" --user-data-dir="{user_data_dir}" --disk-cache-dir="{cache_dir}"'
|
|
)
|
|
|
|
# timings.wait_until(10, 0.5, lambda: any(window.name == '새 시크릿 탭 - Whale' for window in findwindows.find_elements()))
|
|
|
|
timings.wait_until(10, 0.5, lambda: any(window.name == '새 탭 - Whale' for window in findwindows.find_elements()))
|
|
|
|
|
|
# '새 시크릿 탭 - Whale' 창의 PID 검색
|
|
whale_pid = None
|
|
windows = findwindows.find_elements()
|
|
|
|
for window in windows:
|
|
# if window.name == '새 시크릿 탭 - Whale':
|
|
if window.name == '새 탭 - Whale':
|
|
whale_pid = window.process_id
|
|
print(f"'새 시크릿 탭 - Whale' 창을 찾았습니다. PID: {whale_pid}")
|
|
break
|
|
|
|
# PID를 통해 웨일 창 제어
|
|
if whale_pid:
|
|
try:
|
|
whale_app = Application(backend="uia").connect(process=whale_pid)
|
|
whale_window = whale_app.top_window()
|
|
|
|
# 창 포커스 설정 및 컨트롤 요소 출력
|
|
whale_window.set_focus()
|
|
print("=== 초기 상태 ===")
|
|
|
|
address_bar = whale_window.child_window(title="주소창 및 검색창", control_type="Edit")
|
|
address_bar.click_input()
|
|
|
|
# URL 문자열을 직접 입력
|
|
for chunk in [url[i:i+10] for i in range(0, len(url), 10)]:
|
|
address_bar.type_keys(chunk, with_spaces=True)
|
|
address_bar.type_keys("{ENTER}") # 엔터 입력
|
|
|
|
print(f"{url}로 이동 중...")
|
|
|
|
# time.sleep(1)
|
|
|
|
# whale_window.print_control_identifiers()
|
|
|
|
# time.sleep(3)
|
|
|
|
print(f"이미지 우클릭")
|
|
try:
|
|
image = whale_window.child_window(title="누락된 이미지 설명을 확인하려면 컨텍스트 메뉴를 여세요.", control_type="Image")
|
|
|
|
if image.exists():
|
|
image.right_click_input()
|
|
print("이미지 요소에서 우클릭을 수행했습니다.")
|
|
|
|
translate_menu_item = whale_window.child_window(title="쇼핑렌즈로 검색하기", control_type="MenuItem")
|
|
translate_menu_item.click_input()
|
|
print("이미지 번역 명령이 실행되었습니다.")
|
|
time.sleep(10)
|
|
|
|
else:
|
|
print("이미지 요소를 찾을 수 없습니다.")
|
|
except Exception as e:
|
|
print(f"이미지 요소에서 우클릭 중 오류 발생: {e}")
|
|
|
|
|
|
|
|
try:
|
|
with open("control_identifiers.txt", "w", encoding="utf-8") as f:
|
|
# 출력 스트림을 파일로 리다이렉트
|
|
original_stdout = os.sys.stdout # 기존 stdout 저장
|
|
os.sys.stdout = f # stdout을 파일로 리다이렉트
|
|
|
|
whale_window.print_control_identifiers() # 컨트롤 식별자 출력
|
|
|
|
os.sys.stdout = original_stdout # stdout 복원
|
|
print(f"컨트롤 식별자가 {"control_identifiers.txt"}에 저장되었습니다.")
|
|
except Exception as e:
|
|
print(f"컨트롤 식별자 저장 중 오류 발생: {e}")
|
|
|
|
|
|
|
|
except Exception as e:
|
|
print(f"창을 제어할 수 없습니다: {e}")
|
|
else:
|
|
print("'새 시크릿 탭 - Whale' 창을 찾을 수 없습니다.")
|