-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
153 lines (120 loc) · 7.67 KB
/
test.py
File metadata and controls
153 lines (120 loc) · 7.67 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
import asyncio
from browser_use import Agent, BrowserSession, BrowserProfile, ChatAnthropic
from browser_use.browser import BrowserProfile, BrowserSession
# SENSITIVE_DATA 로드
SENSITIVE_DATA = {
"first_name": "JaeYoung",
"last_name": "Lee",
"email": "test@gmail.com",
"country": "대한민국",
"phone_number": "10-1234-5678", # 실제로는 01012345678 또는 12345678 형태로 입력될 수 있음
"gender": "남성", # "남성" 또는 "여성"
# 탑승객 정보
"birth_date": "2001-03-09", # 생년월일
"passenger_passport_number": "M123456789", # 여권 번호 예시
"passenger_passport_expire_date": "2030-12-31", # 여권 만료일 예시
# 신용카드 정보
"credit_card_number": "1234-5678-9012-3456", # 예시 카드 번호
"credit_card_expiry": "12/25", # 카드 만료일
"credit_card_cvc": "123", # 카드 CVC
"credit_card_holder_name": "JaeYoung Lee", # 카드 소유자 이름
"credit_card_type": "Visa", # 카드 종류
}
# 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():
# SENSITIVE_DATA의 birth_date를 년, 월, 일로 분리
birth_year, birth_month, birth_day = SENSITIVE_DATA["birth_date"].split("-")
# 월을 숫자만 남기기 (예: "03" -> "3")
birth_month_numeric = str(int(birth_month))
birth_day_numeric = str(int(birth_day))
return [
f"""
https://www.agoda.com/ko-kr/bookings/details?cid=1844104&itineraryId=G%3ASEL_20250625_G%3ATYO_20250629_1-0-0_ECO_2___23970241&token=AAAA.AAAADDFBX9gJYxKEnOHIzJzTHNupD7EJWxZPLH6Wd5UaYvtRxPbrKo4yfGGgq8dEXJ7%2FkO1SeZ%2FFpFRpFSb3pQmI%2Bh5yKTR6UWAfBWmh3H1L6l8O0gf%2BS7ViEDxiGMa6GyU49kMH2e48f9IhTw1Ul9r3x1vsgVgE%2FZlYzAxdrFoIlDZWcm530ZGGX%2BpqCvxB%2FRqj%2FKn7kBE13U2LHnX91NgMhnSNE%2FGFsgGoqFQVVch4snFHjsAKpXr6LvD%2Bk66TcaMNtPZRF%2FoOg%2BuSg5EQYhC2WQsRmI%2BTW7pn8A3KsaoxL8sPZquKj%2FmdOvOOFZCexkt8kJv1OK8fNROTTyZu6bJZhMzH%2FpQqgiL78Ke7Ecw8zQZSuabnK%2FPIFvdGQdQZlxmDbeM3jFQTmHmXW%2F4ODKeM1To%2FcpsLWy6d8vT%2BExwDLnzmQuWzye4W2xp31hIiew8ZdTvU1rthW5fsuS5L&preferredBundle=1850138144에 접속해 항공권 예약을 진행해.
1. 연락처 정보 입력 섹션에 다음 정보를 입력해:
- '영문 이름(First Name)' 필드에 `<secret>first_name</secret>`을 입력해.
- '영문 성(Last Name)' 필드에 `<secret>last_name</secret>`을 입력해.
- '이메일 주소' 필드에 `<secret>email</secret>`을 입력해.
- '거주 국가/지역' 드롭다운 버튼을 클릭한 후, 드롭다운의 검색창에 `<secret>country</secret>`를 입력하고, 드롭다운 목록에 나타나는 `<secret>country</secret>`의 라디오 버튼 또는 옵션을 한번 클릭하여 선택해.
- '전화번호' 필드 `<secret>phone_number</secret>`를 입력해.
2. 연락처 정보 입력 후, 웹 페이지 하단으로 스크롤해서 다음 단계로 넘어가.
3. 이어서 탑승객 정보(성인) 섹션에 다음 정보를 입력해:
- '성별' 항목에서 `<secret>gender</secret>` 값에 해당하는 gender 라디오 버튼을 한번 클릭하여 선택해. (예: `<secret>gender</secret>`가 "남성"이면 '남성' 라디오 버튼 클릭)
- '영문 이름 & 영문 중간 이름' 필드에 `<secret>first_name</secret>`을 입력해. (중간 이름이 없다면 이름만 입력)
- '영문 성(Last Name)' 필드에 `<secret>last_name</secret>`을 입력해.
- '생년월일' 섹션:
- '년도' 입력 필드에 `<secret>birth_date</secret>`의 연도 부분({birth_year})을 입력해.
- '월' 드롭다운 메뉴를 클릭하여 `<secret>birth_date</secret>`의 월 부분({birth_month_numeric})을 선택해.
- '일' 입력 필드에 `<secret>birth_date</secret>`의 일 부분({birth_day_numeric})을 입력해.
- '국적' 드롭다운 버튼을 클릭한 후, 검색창에 `<secret>country</secret>`를 입력하고, 드롭다운 목록에 나타나는 `<secret>country</secret>` 라디오 버튼 또는 옵션을 한번 클릭하여 선택해.
- **선택 후, 국적 필드에 `<secret>country</secret>`가 올바르게 표시되는지 확인하고, 재선택하지 마.**
- '여권' 섹션(여권번호, 여권 발행 국적, 여권 만료일):
- **만약 여권 관련 정보 입력 항목 혹은 필드가 없다면 이 작업은 넘어가!**
- '여권번호' 필드에 `<secret>passport_number</secret>`를 입력해.
- '여권 발행 국가' 드롭다운 버튼을 클릭한 후, 검색창에 `<secret>country</secret>`를 입력하고, 드롭다운 목록에 나타나는 `<secret>country</secret>` 라디오 버튼 또는 옵션을 한번 클릭하여 선택해.
- **선택 후, 필드에 `<secret>country</secret>`가 올바르게 표시되는지 확인하고, 재선택하지 마.**
- '여권 만료일' 섹션:
- '년도' 입력 필드에 `<secret>passport_expire_date</secret>`의 연도 부분을 입력해.
- '월' 드롭다운 버튼을 클릭하여 드롭다운 메뉴에서 `<secret>passport_expire_date</secret>`의 월 부분에 해당하는 라디오 버튼 또는 옵션을 한번 클릭하여 선택해.
- '일' 입력 필드에 `<secret>passport_expire_date</secret>`의 일 부분을 입력해.
3. 모든 필수 정보 입력 후, 하단에 있는 체크 항목의 '모든 항목에 동의'하는 체크박스를 클릭해 체크하고, 예약을 계속 진행해.
4. 부가서비스 및 여행 보험 관련한 항목은 사용하지 않거나 선택하지 않고 결제페이지로 이동해.
"""
]
extend_system_message = f"""
REMEMBER the most important RULE:
Make decisions at each stage carefully, and once done correctly, never repeat the task
"""
TASK = make_task_prompt()
llm = ChatAnthropic(
model="claude-sonnet-4-0",
)
browser_session = BrowserSession(
browser_profile=BrowserProfile(
wait_for_network_idle_page_load_time=1.0,
viewport={"width": 1280, "height": 1100},
viewport_expansion=1500,
),
)
# Agent 설정
agent = Agent(
extend_system_message=extend_system_message,
browser_session=browser_session,
task=TASK,
llm=llm,
sensitive_data=SENSITIVE_DATA,
override_system_message="",
enable_memory=True,
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,
max_steps=150,
)
if __name__ == "__main__":
asyncio.run(main())