728x90
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
from random import *
from datetime import datetime
import telegram

bot = telegram.Bot(token='')
chat_id

ID = ""
PW = "!"
target_date="27" #원하는 날짜

bot.sendMessage(chat_id, datetime.today().strftime("%Y/%m/%d %H:%M:%S")+" 유성CC "+target_date+"일 예약 START")

browser = webdriver.Chrome('chromedriver')

time.sleep(1)
#로그인 처리
search = browser.find_element_by_xpath('//*[@id="txtId"]')
search.send_keys(ID)

search = browser.find_element_by_xpath('//*[@id="txtPw"]')
search.send_keys(PW)
search.send_keys(Keys.RETURN)

time.sleep(1)

print(browser.window_handles)

time.sleep(1)
#코로나 팝업 뜨는거 있으면 종료
if len(browser.window_handles) > 1:
    browser.switch_to_window(browser.window_handles[1])
    browser.close()

    browser.switch_to_window(browser.window_handles[0])


# //*[@id="contents"]/table/tbody/tr[4]/td[1]/p 에콜리안
time.sleep(5)
#//*[@id="calendar-body"]/tr[2]/td[4]

while True:
    for i in range(1,5):
        for j in range(1,7):
            search_row = browser.find_element_by_xpath('//*[@id="calendar-body"]/tr['+str(i)+']/td['+str(j)+']')
            search_row_innerhtml = search_row.get_attribute('innerHTML')
           
            search_row_date = search_row_innerhtml[0:search_row_innerhtml.find('<')]
                       
            if search_row_date == target_date:
                search_row_class = search_row.get_attribute('class')
                print(datetime.today().strftime("%Y/%m/%d %H:%M:%S")+' > '+search_row_date+'일 '+search_row_class)
                if search_row_class == 'possible':
                    search = browser.find_element_by_xpath('//*[@id="calendar-body"]/tr['+str(i)+']/td['+str(j)+']')        
                    search.send_keys(Keys.RETURN)
                   
                    if browser.find_element_by_xpath('//*[@id="time-grid"]/tr[1]/td[5]') == '18홀': #18홀만 예약
                        search = browser.find_element_by_xpath('//*[@id="time-grid"]/tr[1]/td[6]/a')        
                        search.send_keys(Keys.RETURN)
                        bot.sendMessage(chat_id, datetime.today().strftime("%Y/%m/%d %H:%M:%S")+" 유성CC "+target_date+"일 예약")
                    else:
                        browser.refresh()
                        time.sleep(6)
                       
                else:
                    browser.refresh()
                    time.sleep(6)
728x90

+ Recent posts