Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- SQL
- 주피터노트북그래프
- sql따라하기
- python데이터분석
- 맷플롯립
- sql연습
- 파이썬수업
- python알고리즘
- 파이썬
- Python
- 파이썬크롤링
- 주피터노트북
- 주피터노트북판다스
- 파이썬알고리즘
- python수업
- 팀플기록
- 수업기록
- SQLSCOTT
- matplotlib
- 데이터분석시각화
- 파이썬차트
- sql연습하기
- 주피터노트북데이터분석
- SQL수업
- 판다스그래프
- 파이썬데이터분석주피터노트북
- 판다스데이터분석
- 주피터노트북맷플롯립
- 파이썬데이터분석
- 파이썬시각화
Archives
- Today
- Total
IT_developers
Python RPA(업무자동화) 개념 및 실습 - 크롤링(selenium)(2) 본문
RPA(Robotic Process Automation)
- 웹, 윈도우, 어플리케이션(엑셀 등)을 사전에 설정한 시나리오에 따라 자동적으로 작동하여 수작업을 최소화하는 일련의 프로세스
- RPA 사용 소프트웨어
- Uipath, BluePrism, Automation Anywhere, WinAutomation
- RPA 라이브러리
- pyautogui, pyperclip, selenium
크롤링 : 웹 사이트, 하이퍼링크, 데이터 정보 자원을 자동화된 방법으로 수집, 분류, 저장하는 것
Selenium
- 브라우저 자동화 개념 적용
- webdriver 이용해서 브라우저 조작, 자동으로 일을 시킬 수 있음
- 웹을 테스트하기 위한 프레임워크
- 자바, 파이썬, C#, 자바 스크립트 등 언어들에서 사용 가능
- 소스 가져오기 + 파싱도 가능
- 브라우저도 접근하기 때문에 차단 될 확률도 적어짐
- 요소찾기
- find_element() : 하나의 요소를 찾을 때
- find_elements() : 여러개의 요소를 찾을 때
- 아이디 값 : find_element(By.ID, "ID 값")
- CSS 선택자 : find_element(By.CSS_SELECTOR, "#선택자 값")
- 클래스 : find_element(By.CLASS_NAME, "NAME 값")
- Xpath : find_element(By.XPATH, '//*[@Xpath 값"]')
- By.NAME, By.CLASS_NAME, By.CSS_SELECTOR, By.ID, By.LINK_TEXT, By.PARTIAL_LINK_TEXT, By.TAG_NAME, By.XPATH
RPAbasic\crawl\selenium1 폴더 - 6_danawa.py
다나와 사이트 로그인 하기
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.maximize_window()
time.sleep(1)
# 로그인 버튼 찾기
login = browser.find_element(By.CLASS_NAME, "btn_user--login")
login.click()
# 페이지 이동이 있으니 시간
time.sleep(1)
# 아이디 입력 찾기
userid = browser.find_element(By.ID, "danawa-member-login-input-id")
userid.clear()
userid.send_keys("본인 아이디")
# 비밀번호 입력 찾기
password = browser.find_element(By.ID, "danawa-member-login-input-pwd")
password.clear()
password.send_keys("본인비밀번호")
password.send_keys(Keys.ENTER)
time.sleep(3)
browser.quit()



RPAbasic\crawl\selenium1 폴더 - 7_ecos.py
한국은행 결제 통계 시스템에서 엑셀 자료 다운로드
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.maximize_window()
time.sleep(3)
# 100대 통계지표찾기
browser.find_element(
By.XPATH, '//*[@id="root"]/div[5]/div/div[2]/div[4]/div[1]/div[3]/ul/li[1]/a'
).click() # 찾으면 바로 클릭
time.sleep(2)
# 엑셀 다운로드 버튼
browser.find_element(By.CSS_SELECTOR, "div.exelDown.partition-right > button").click()
time.sleep(3)
browser.quit()



RPAbasic\crawl\selenium1 폴더 - 8_gmarket.py
G마켓 접속 후 태블릿 검색하기
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.maximize_window()
time.sleep(3)
# gmarket 검색창 찾기
element = browser.find_element(By.NAME, "keyword")
element.send_keys("태블릿")
element.send_keys(Keys.ENTER)
time.sleep(3)
browser.quit()

RPAbasic\crawl\selenium1 폴더 - 9_youtube.py
Youtube에서 아이유 검색 후 결과 출력
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.maximize_window()
time.sleep(2)
# 검색어 넣기
# element = browser.find_element(By.ID, "search")
element = browser.find_element(By.NAME, "search_query")
element.send_keys("아이유")
element.send_keys(Keys.ENTER)
time.sleep(2)
# 검색 결과 출력
titles = browser.find_elements(By.TAG_NAME, "h3")
for title in titles:
print(title.text)
time.sleep(3)
browser.quit()


RPAbasic\crawl\selenium1 폴더 - 10_selector.py
검색 창 다양하게 방법으로 찾기 - 다 같은 결과가 나옴.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.maximize_window()
# 아이디 값으로 찾기
element = browser.find_element(By.ID, "id-search-field")
# css 선택자로 찾기
element = browser.find_element(By.CSS_SELECTOR, "#id-search-field")
# 클래스 이름으로 찾기
element = browser.find_element(By.CLASS_NAME, "search-field")
# Xpath로 찾기 - 복사 필요
element = browser.find_element(By.XPATH, '//*[@id="id-search-field"]')
element.send_keys("python")
element.send_keys(Keys.ENTER)
time.sleep(3)
browser.quit()

RPAbasic\crawl\selenium1 폴더 - 11_screenshot.py
다음에서 콘서트 검색 후 관련 검색어 출력 후 스크린샷 저장
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome()
browser.maximize_window()
time.sleep(2)
# 검색창 찾기
element = browser.find_element(By.NAME, "q")
# 검색어 넣기 + 엔터
element.send_keys("콘서트")
element.send_keys(Keys.ENTER)
time.sleep(2)
# 관련검색어 추출
lists_top = browser.find_elements(By.CSS_SELECTOR, "#netizen_lists_top > span.wsn")
for item in lists_top:
print(item.text)
# 현재 화면 캡쳐 - 기본 캡쳐 방식.png, jpg==> 경고 메세지 뜸
browser.save_screenshot("./RPAbasic/crawl/download/image.png")
time.sleep(3)
browser.quit()


'Python' 카테고리의 다른 글
Python RPA(업무자동화) 개념 및 실습 - 크롤링(selenium)(4) (0) | 2022.10.06 |
---|---|
Python RPA(업무자동화) 개념 및 실습 - 크롤링(selenium)(3) (1) | 2022.10.05 |
Python RPA(업무자동화) 개념 및 실습 - 크롤링(selenium)(1) (0) | 2022.10.03 |
Python RPA(업무자동화) 개념 및 실습 - 크롤링(정규표현식)(2) (0) | 2022.10.02 |
Python RPA(업무자동화) 개념 및 실습 - 크롤링(정규표현식)(1) (1) | 2022.10.01 |
Comments