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
import re

def cleanhtml(raw_html):
  cleanr = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
  cleantext = re.sub(cleanr, '', raw_html)
  return cleantext

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="txtPwd"]')
search.send_keys(PW)
search.send_keys(Keys.RETURN)

time.sleep(3)


time.sleep(3)

while True:
#     if browser.find_element_by_xpath('//*[@id="remainSecond"]').get_attribute('innerHTML').find("5")>=0:
#         for i in range(2,7):
#             for j in range(1,8):
#                 search_row = browser.find_element_by_xpath('//*[@id="contents"]/table/tbody/tr['+str(i)+']/td['+str(j)+']')
#                 search_row_innerhtml = search_row.get_attribute('innerHTML')

#                 cleaned_search_row = cleanhtml(search_row_innerhtml).lstrip().rstrip().replace("  ","")

#                 if cleaned_search_row.find(target_date) > 0:
#                     print(datetime.today().strftime("%Y/%m/%d %H:%M:%S")+' > '+search_row_date+'일 '+cleaned_search_row)
#                     if cleaned_search_row.find("예약가능") > 0:
#                         search = browser.find_element_by_xpath('//*[@id="contents"]/table/tbody/tr['+str(i)+']/td['+str(j)+']/p')  
#                         search.send_keys(Keys.RETURN)
                       
#                         brn = browser.find_element_by_xpath('//*[@id="rspop_01"]/div[1]/div[3]/div/a[1]')  
#                         search.send_keys(Keys.RETURN)
#                         bot.sendMessage(chat_id, datetime.today().strftime("%Y/%m/%d %H:%M:%S")+" 에콜리안CC "+target_date+"일 예약")
#     else:
#         time.sleep(3)
    try:  
        for i in range(2,7):
            for j in range(1,8):
                search_row = browser.find_element_by_xpath('//*[@id="contents"]/table/tbody/tr['+str(i)+']/td['+str(j)+']')
                search_row_innerhtml = search_row.get_attribute('innerHTML')

                cleaned_search_row = cleanhtml(search_row_innerhtml).lstrip().rstrip().replace("    ","")

                if cleaned_search_row.find(target_date) >= 0:
                    print(datetime.today().strftime("%Y/%m/%d %H:%M:%S")+' > '+cleaned_search_row)
                    if cleaned_search_row.find("예약가능") > 0:
                        search = browser.find_element_by_xpath('//*[@id="contents"]/table/tbody/tr['+str(i)+']/td['+str(j)+']/p')  
                        search.send_keys(Keys.RETURN)

                        brn = browser.find_element_by_xpath('//*[@id="rspop_01"]/div[1]/div[3]/div/a[1]')  
                        search.send_keys(Keys.RETURN)
                        bot.sendMessage(chat_id, datetime.today().strftime("%Y/%m/%d %H:%M:%S")+" 에콜리안CC "+target_date+"일 예약")
        time.sleep(5)
    except:
        print("StaleElementReferenceException exception occured!")
        time.sleep(5)
728x90

+ Recent posts