일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- C++
- Leviathan
- 워게임
- 하드링크
- C언어
- 시스템프로그래밍
- kernel
- 포너블
- 시스템 프로그래밍
- Pwnable.kr
- 리버싱
- 리눅스 커널
- 시그널
- 어셈블리어
- pwncollege
- 프로그래밍
- css
- pwn.college
- 시스템
- Bandit
- radare2
- 알고리즘
- write up
- wargame
- 시스템해킹
- 리눅스
- 커널
- multiplexing
- 컴퓨터구조
- 리눅스커널
Archives
- Today
- Total
Computer Security
#4 Selenium을 이용한 매크로(자동배정) 본문
악용할 예시가 있기 때문에
코드 몇줄은 넣지 않고 올린다.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import schedule
import time
import datetime
import sys
import datetime as dt
driver = webdriver.Chrome('./chromedriver.exe')
# 사이즈조절
driver.set_window_size(1920, 1080) # (가로, 세로)
driver.get('site') # 페이지 이동
print(driver.window_handles)
driver.switch_to.frame(driver.find_element(By.XPATH, "//div[@class='leftLoginBox']/iframe[@title='login']"))
userId.send_keys('ID') # 로그인 할 계정 id
userPwd.send_keys('PW') # 로그인 할 계정의 패스워드
userPwd.send_keys(Keys.ENTER)
def wait_until(xpath_str):
WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, xpath_str)))
driver.get('예매')
#ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
#예매 창
endhope=False
while not endhope:
tim=dt.datetime.now()
if tim.second>=59 and tim.microsecond>800000:
driver.refresh()
endhope=True
print(tim)
else:
time.sleep(0.1)
print(tim)
#정해진 시간에 새로 고침
wait_until('//*[@id="div_checkDontsee_PT002_46_1"]/div[2]/button')
pop.click()
wait_until('/html/body/div[6]/div[4]/div[4]/div[2]/div[5]')
# 예매하기 눌러서 새창이 뜨면 포커스를 새창으로 변경
print(driver.window_handles)
driver.switch_to.window(driver.window_handles[1])
print(driver.window_handles)
#좌석 일반석 선택
wait_until('/html/body/div[1]/div[3]/div[2]/div[1]/a')
seat = driver.find_element(By.XPATH, '/html/body/div[1]/div[3]/div[2]/div[1]/a')
seat.click()
#자동배정 클릭
wait_until('/html/body/div[1]/div[3]/div[2]/div[3]/a[1]/img')
click1 = driver.find_element(By.XPATH,'/html/body/div[1]/div[3]/div[2]/div[3]/a[1]/img')
click1.click()
내가 주목할 코드는 while 문과 if 문을 통해
현재 시간을 계속 받아오면서 내가 원하는 시간까지 무한루프를 돌다가 빠져나오는 코드이다.
endhope=False
while not endhope:
tim=dt.datetime.now()
if tim.second>=59 and tim.microsecond>800000:
driver.refresh()
endhope=True
print(tim)
else:
time.sleep(0.1)
print(tim)
셀레니움을 통해 59.8초에 정확히 새로고침되는 매크로 이다.
중요 코드 몇줄은 삭제했으니..ㅎㅎ 괜찮겠지
'프로그래밍 > Python 웹 스크래핑' 카테고리의 다른 글
#5 Selenium을 이용한 매크로(좌석선택) (0) | 2022.07.02 |
---|---|
#3 XPATH를 이용한 주요 뉴스 불러오기 (0) | 2022.06.29 |
#2 XPATH를 활용한 네이버웹툰 실시간 급상승 불러오기 (0) | 2022.06.28 |
#1 XPATH를 활용한 네이버 항공권 최저가 불러오기 (0) | 2022.06.27 |
Comments