0w0

[selenium] 클릭 및 입력 전송 CLI (파이썬 자동 로그인 및 자동화) 본문

Coding/Python

[selenium] 클릭 및 입력 전송 CLI (파이썬 자동 로그인 및 자동화)

0w0 2019. 8. 9. 20:36
728x90
반응형

CLI로 백그라운드 동작이기 때문에 implicitly_wait(), time.sleep()은 굳이 안줘도됨.

GUI도 굳이 대기 시간을 주지 않아도 퍼포먼스가 좋음.

 

CLI 테스트 부분은 추가 모듈과 추가 호출을 통해 --headless 옵션을 사용함 (걍 phantomjs를 사용해됨)

from selenium.webdriver.chrome.options import Options

chrome_options=Options()
chrome_options.add_argument("--headless") #CLI
bs_driver=webdriver.Chrome(chrome_options=chrome_options, executable_path='C:\chromedriver')

 

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
#coding=utf-8
#IMPORT Area
import sys
import io
import time
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
 
#CODE Area
print(sys.version)
 
# browser 엔진에서 파싱되는 시간을 대기(중간 파싱완료되면 대기종료)
#bs_driver.implicitly_wait(2)
 
# process 에서 시간을 대기
#time.sleep(1)
 
#implicitly_wait()와 time.sleep()의 차이점
#1. 대기 대상이 browser 엔진 함수와 프로세스
#2. implicitly_wait()는 대기 중 파싱이 완료되면 바로 수행
#3. time.sleep()은 입력된 대기시간 만큼 무조건 프로세스 대기
 
#크롬 드라이버 및 옵션 호출
chrome_options=Options()
chrome_options.add_argument("--headless"#CLI
bs_driver=webdriver.Chrome(chrome_options=chrome_options, executable_path='C:\chromedriver')
 
 
# browser 엔진에서 파싱되는 시간을 1초 대기
#bs_driver.implicitly_wait(1)
 
bs_driver.get('URLURL')
 
bs_driver.find_element_by_xpath('').click()
 
# process 에서 시간을 1초 대기
#time.sleep(1)
 
bs_driver.find_element_by_xpath('').send_keys('')
 
#time.sleep(3)
 
#호출한 드라이브 종료
bs_driver.quit()
 
cs

 

 

728x90
반응형
Comments