Playwright 핵심 사용법 정리
·
python/python_selenium
Selenium 은 브라우저를 제어하여 자동으로 테스트를 진행하는 도구이다.하지만 최근에 Playwright 를 사용하는 환경도 많은데 두 도구의 차이와 기본 사용방법을 알아보려 한다. 먼저 Selenium 은 W3C WebDriver 프로토콜을 사용하기 때문에 코드가 실행될 때마다HTTP 요청을 보내고 응답을 받는 방식으로, 각 명령마다 네트워크 오버헤드가 발생한다. 반면 Playwright 는 WebSocket 을 활용하여 브라우저와 단일 연결을 맺고 양방향 통신을 수행한다.따라서 브라우저 내부 이벤트에 직접 접근할 수 있어 실행 속도가 빠르고 응답 지연이 적다. Playwright 의 딱 하나 단점이 있다면, 최신 모던 브라우저 엔진만 지원하기 때문에레거시 브라우저에서 테스트를 해야만 한다면 Sel..
python + selenium, bs4 환경 세팅하기
·
python/python_selenium
1. python 다운로드https://www.python.org/downloads/ 2.python 을 path 에 추가하기 선택 후 install Now3. visual studio code 다운로드 (다음버튼 계속누르면 됨) Visual Studio Code - Code Editing. RedefinedVisual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.code.vi..
selenium_quiz2
·
python/python_selenium
- 웹스크래핑을 이용하여 나만의 비서를 만들기 - 네이버에서 오늘 서울의 날씨 정보를 가져옴. 다음 뉴스 홈에서 뉴스 3건을 가져옴 (헤드라인이 현재 사라짐) it뉴스 3건을 가져옴. 해커스 어학원 홈페이지에서 오늘의 회화 지문을 가져옴. # 웹스크래핑을 이용하여 나만의 비서를 만들기 # 1. 네이버에서 오늘 서울의 날씨 정보를 가져옴. # 2. 다음 뉴스 홈에서 뉴스 3건을 가져옴 (헤드라인이 현재 사라짐) # 3. it뉴스 3건을 가져온다. # 4. 해커스 어학원 홈페이지에서 오늘의 회화 지문을 가져온다. from bs4 import BeautifulSoup import requests import random import re def create_soup(url): print("="*50) head..
selenium_quiz1
·
python/python_selenium
목적 : 네이버 부동산에서 송파 헬리오시티 검색 후 목록 추출하기 # 네이버 부동산에서 `송파 헬리오시티` 검색 후 목록 추출하기 from bs4 import BeautifulSoup import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys browser = webdriver.Chrome() url = "" browser.get(url) time.sleep(1) # 송파 헬리오시티로 이동 후 목록이 로딩될동안 대기. items = browser.find_element(By.ID, "search_input") items.se..
Headless 크롬
·
python/python_selenium
from bs4 import BeautifulSoup import time from selenium import webdriver options = webdriver.ChromeOptions() # headless 즉, 창을 띄우지않고 랜더링을 통해 크롤링 가능 # 다만 해당의 경우, user-agent가 headless로 인식되어 몇몇 사이트에서 막을 수 있다. options.headless = True options.add_argument("window-size=1920x1080") # 아래와 같이 user-agent를 나와 같은 상태로 만들 수 있음. options.add_argument("user-agent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleW..
Selenium 활용2
·
python/python_selenium
import requests from bs4 import BeautifulSoup header = {'User-Agent':("Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36") ,"Accept-Language":"ko-KR,ko"} # 한글 언어 웹페이지를 불러옴 url = "" res = requests.get(url, headers=header) res.raise_for_status() soup = BeautifulSoup(res.text, "lxml") # with open("movie.html", "w", encoding="utf8") as..
Selenium 활용1
·
python/python_selenium
목표 : 네이버 항공에서 제주도행 항공권 찾기 from selenium import webdriver from selenium.webdriver.common.by import By # webdriverWait을 사용하기 위한 import from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time def wait_until(xpath_str): # 아래값이 나올때까지 기다림 ( 다만 나오지 않는 경우 최대 3초까지 기다림. ) WebDriverWait(browser, 3).until(EC.presence_of_element_loc..
Selenium 심화
·
python/python_selenium
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys # webdriverWait을 사용하기 위한 import from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time browser = webdriver.Chrome() browser.get("") # 로그인 버튼을 클릭 후 이동 elem = browser.find_element(By.CLASS_NAME,"link..