오늘 날짜 부분을 공통으로 사용하도록 수정, 대기 시간 지정 방식에서 갱신될 때까지 대기하도록 수정.

This commit is contained in:
2025-06-27 13:31:30 +09:00
parent 69e0156e97
commit 2383f6ebb6

View File

@ -9,6 +9,8 @@ import os
import time import time
import tempfile import tempfile
from config import TODAY
# 크롬 옵션 설정 # 크롬 옵션 설정
options = Options() options = Options()
options.add_argument('--headless') options.add_argument('--headless')
@ -55,16 +57,14 @@ try:
driver.quit() driver.quit()
exit(1) exit(1)
time.sleep(2) # 페이지 반영 대기 # 캡처 대상 요소가 확실히 나타날 때까지 명시적 대기
# 캡처 대상 요소 대기 후 찾기
target_element = wait.until(EC.presence_of_element_located( target_element = wait.until(EC.presence_of_element_located(
(By.XPATH, '/html/body/div[2]/section/div/div[2]') (By.XPATH, '/html/body/div[2]/section/div/div[2]')
)) ))
# 저장 경로 설정 # 저장 경로 설정
timestamp = datetime.now().strftime('%Y%m%d') save_path = os.path.join(script_dir, f'weather_capture_{TODAY}.png')
save_path = os.path.join(script_dir, f'weather_capture_{timestamp}.png')
# 요소 스크린샷 저장 # 요소 스크린샷 저장
target_element.screenshot(save_path) target_element.screenshot(save_path)