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
| import time
import sys
import os
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
wait_sec = 2
########################################################################
id = 'ID' # 아이디
pw = 'PW' # 비밀번호
date = '01.22' # 예약 날짜 (Ex: 01.02)
where = 'PARK' # PARK or VALLEY
whattime = '09:37' # 예약 시간 (Ex: 11:20)
########################################################################
def open_Driver():
options = Options()
options.add_argument('--user-agent=Mozilla/5.0 (Linux; Android 13; SM-G991N Build/TP1A.220624.014; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/102.0.5005.189 Whale/1.0.0.0 Crosswalk/27.102.0.30 Mobile Safari/537.36 NAVER(inapp; search; 2000; 12.3.7)')
options.add_argument('--headless=new') # 헤드레스
options.add_argument('--incognito') # 익명화
options.add_argument('--lang=ko_KR') # 언어 설정
options.add_argument('--window-size=1920x1080') # pc용 사이즈
options.add_argument('--start-maximized') # 브라우저가 최대화된 상태로 실행
options.add_argument('--disable-gpu') # 하드웨어 가속화 끔
options.add_argument('--disable-software-rasterizer') # 소프트웨어 랜더링 가속화 끔
options.add_argument('--disable-dev-shm-usage') # 공유메모리 사용 끔
options.add_argument('--blink-settings=imagesEnabled=false') # 이미지 로딩 비활성화
options.add_argument('--no-sandbox') # 샌드박스 비활성화
#options.add_experimental_option("detach", True) # 창 종료 방지
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
return driver
def close_Driver(driver):
driver.quit()
def login(driver, id, pw):
login_url = 'https://www.parkvalley.co.kr/Mobile/Member/LogIn.aspx'
driver.get(login_url)
xpath_id = '//input[@id="ctl00_contents_userID"]'
xpath_pw = '//input[@id="ctl00_contents_userPassword"]'
xpath_btn = '//a[@class="loginBtn"]'
wait = WebDriverWait(driver, wait_sec)
wait.until(EC.presence_of_element_located((By.XPATH, xpath_id)))
driver.find_element(By.XPATH, xpath_id).send_keys(id)
driver.find_element(By.XPATH, xpath_pw).send_keys(pw)
driver.find_element(By.XPATH, xpath_btn).click()
def booking(driver, where, date, whattime):
book_url = 'https://www.parkvalley.co.kr/Mobile/Booking/ReservationCalendar.aspx'
driver.get(book_url)
xpath_date = f'//a[text()="{date}"]'
xpath_time = f'//tr[td[1]="{where}" and td[2]="{whattime}"]/td/a'
xpath_btn = '//a[@id="ctl00_contents_lnkBtnReserveOk"]'
wait = WebDriverWait(driver, wait_sec)
wait.until(EC.presence_of_element_located((By.XPATH, xpath_date)))
driver.find_element(By.XPATH, xpath_date).click()
wait.until(EC.presence_of_element_located((By.XPATH, xpath_time)))
driver.find_element(By.XPATH, xpath_time).click()
driver.find_element(By.XPATH, xpath_btn).click()
# 팝업창 뜰때 확인 버튼 누름
driver.switch_to.alert.accept()
time.sleep(1)
# 팝업창 뜰때 확인 버튼 누름
driver.switch_to.alert.accept()
return True
def main():
print(f'[+] Start ({time.strftime("%Y.%m.%d - %H:%M:%S")})')
try:
driver = open_Driver()
login(driver, id, pw)
while True:
try:
if booking(driver, where, date, whattime):
close_Driver(driver)
print('\n[-] End!')
break
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(f'file name: {str(fname)}')
print(f'error type: {str(exc_type)}')
print(f'error msg: {str(e)}')
print(f'line number: {str(exc_tb.tb_lineno)}')
time.sleep(1)
continue
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(f'file name: {str(fname)}')
print(f'error type: {str(exc_type)}')
print(f'error msg: {str(e)}')
print(f'line number: {str(exc_tb.tb_lineno)}')
if __name__ == '__main__':
main()
|