-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter-test.py
More file actions
165 lines (122 loc) · 7.32 KB
/
filter-test.py
File metadata and controls
165 lines (122 loc) · 7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import asyncio
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_ollama import ChatOllama
from browser_use import Agent, BrowserSession, BrowserProfile
from browser_use.browser import BrowserProfile, BrowserSession
import os
# # DOM 모니터링 함수
# async def monitor_dom(agent: Agent):
# page = await agent.browser_session.get_current_page()
# if not page:
# print("⛔️ No current page found")
# return
# # DOM이 로드될 때까지 대기
# await page.wait_for_load_state("domcontentloaded")
# print("✅ DOM is ready")
# # 네트워크 요청이 완료될 때까지 대기
# await page.wait_for_load_state("networkidle")
# print("✅ Network is idle")
# # 추가적으로 특정 요소가 나타날 때까지 대기할 수도 있음
# # await page.wait_for_selector('some-selector')
def make_task_prompt():
return """
새로고침은 절대로 하지마.
# 1. 가는 여정 (2025-06-18: 인천(ICN) → 도쿄(NRT))
https://www.agoda.com/ko-kr/flights/results?tag=eeeb2a37-a3e0-4932-8325-55d6a8ba95a4&gclid=Cj0KCQjw9O_BBhCUARIsAHQMjS71DE5fQ2J7RklWkwp3k_Y7XgsbbcVuOWnfcskfdAi6YmCIGs7m_BcaApVlEALw_wcB&site_id=1922887&departureFrom=ICN&departureFromType=1&arrivalTo=NRT&arrivalToType=1&departDate=2025-06-18&returnDate=2025-06-21&searchType=2&cabinType=Economy&adults=1&sort=8 에 접속한 뒤, 아래 단계를 **정확히 한 번씩만** 순서대로 수행해줘:
0. 페이지가 완전히 로드될 때까지 최소 3초 기다리기. 이 시간 동안 아무것도 하지 않기.
1. **대한항공 필터 적용 (반복 금지)**:
a. 좌측 필터 영역에서 '항공사' 섹션을 찾기.
b. '모든 항공사 보기' 또는 '항공사 40곳 모두 보기' 링크가 보이면 **딱 한 번만 클릭해서 전체 목록 펼치기**.
c. 목록이 확장되면, 'Korean Airlines' 또는 '대한항공' 텍스트가 포함된 체크박스를 **반드시 찾기**.
d. 체크박스가 이미 체크되어 있으면 **아무 동작도 하지 말고 즉시 다음 단계로 넘어가기**.
e. 체크박스가 체크되어 있지 않으면 **딱 한 번만 클릭하여 체크 상태로 만들기**.
f. 클릭을 했으면 3초 대기.
g. 클릭 후에는, 필터가 실제로 적용됐는지 시각적으로 반드시 확인하기:
- 항공편 목록이 '대한항공' 항공편으로만 표시되는지,
- 체크박스가 체크된 상태인지 확인.
2. **필터 적용 확인**:
a. 항공편 목록에 로딩 표시가 있으면 충분히 기다리기.
b. 목록 내 모든 항공편의 항공사가 '대한항공' 또는 'Korean Airlines'인지 확인.
3. **최저가 항공편 선택**:
a. 위 2단계에서 확인된 '대한항공' 항공편 목록 중에서 가장 가격이 낮은 항공편을 선택해줘.
===================================================
# 2. 오는 여정 (2025-06-21: 도쿄(NRT) → 인천(ICN))
4. 가는편 최저가 항공편 선택 후, 자동으로 오는편 항공편 목록이 화면에 표시될 것이다. 별도의 탭 전환 또는 버튼 클릭 없이 **자동으로 보이는 오는편 화면에서 작업을 계속 진행해줘**.
5. 오는편 탭이 완전히 로드될 때까지 최소 3초 기다리기.
6. **대한항공 필터 적용 (반복 금지)**:
a. 좌측 필터 영역에서 '항공사' 섹션 찾기.
b. '모든 항공사 보기' 클릭은 딱 한 번만.
c. 'Korean Airlines' 체크박스 찾기.
d. 이미 체크되어 있으면 클릭하지 말고 바로 다음으로.
e. 체크 안 되어 있으면 딱 한 번만 클릭해서 체크하기.
f. 체크 상태로 바뀌면 다시 클릭 또는 해제 절대 금지.
g. 필터 적용 확인 (목록 내 항공사명과 체크박스 상태).
7. **필터링 결과 확인**:
a. 로딩 표시가 있으면 충분히 기다리기.
b. 모든 항공편 항공사명이 '대한항공' 또는 'Korean Airlines'인지 확인.
8. **최저가 항공편 선택**:
a. 가장 저렴한 항공편 하나 선택.
9. **예약 절차 진행**:
a. 연락처 등 정보 입력.
---------------------------------------------------
※ 새로고침(페이지 강제 재로딩)은 절대 하지 말 것.
※ 모든 이동은 페이지 내 UI 조작(클릭, 탭 전환 등)으로만 진행.
※ 필터 적용 시 중복 클릭 금지, 필터 상태 유지 철저.
"""
extend_planner_message = f"""
REMEMBER the most important RULE:
Make decisions at each stage carefully, and once done correctly, never repeat the task.
If you find yourself setting the exact same 'Next goal' as the previous step, or performing the exact same action on the same element multiple times without the desired page change or a clear visual confirmation of success, critically re-evaluate:
1. Is the goal truly not achieved, or am I misinterpreting the page state? (e.g., Did the filter *actually* apply even if I didn't see a spinner? Is the checkbox *already* checked?)
2. Is the page still loading or updating from my previous action? Consider waiting a bit longer, especially if the task involves filtering or loading new content.
3. Did I click the correct element? Is there a more specific or reliable element I should target (e.g., a checkbox directly associated with the text, or an element with a unique ID)? Double-check the element's properties.
4. If an action is not working as expected after a couple of tries, do not repeat it endlessly. Re-assess the page, your understanding of the task, and consider a slightly different approach or element. For example, if clicking a checkbox isn't working, is there an "Apply" button I missed?
Avoid getting stuck in a loop. If a specific action on a specific element isn't working, repeating it won't help. Assume your previous action *might* have worked and look for evidence.
"""
TASK = make_task_prompt()
llm = ChatGoogleGenerativeAI(
model="gemini-2.0-flash",
cache=False,
)
# llm = ChatOllama(
# base_url="http://1.228.118.214:11434",
# model="qwen:32b",
# )
browser_session = BrowserSession(
browser_profile=BrowserProfile(
wait_for_network_idle_page_load_time=1.0,
no_viewport=False,
window_size={"width": 1280, "height": 1100}
),
)
# Agent 설정
agent = Agent(
extend_system_message=extend_planner_message,
browser_session=browser_session,
task=TASK,
llm=llm,
override_system_message="",
max_actions_per_step=1,
)
async def main():
# 사용자 입력
# departure = input("출발지(ex: Seoul): ").strip()
# arrival = input("도착지(ex: Tokyo): ").strip()
# depart_date = input("출발 날짜(ex: 2025-06-02): ").strip()
# return_date = input("도착 날짜(ex: 2025-06-10): ").strip()
# num_people = input("탑승 인원수(ex: 1): ").strip()
# 사용자 입력 - 테스트용 예시값
# departure = "Seoul"
# arrival = "Tokyo"
# depart_date = "2025-06-20"
# return_date = "2025-06-30"
# num_people = "1"
await agent.run(
# on_step_start=monitor_dom,
# on_step_end=monitor_dom,
max_steps=150,
)
# 종료 전 대기
await asyncio.sleep(1000000)
if __name__ == "__main__":
asyncio.run(main())