본문 바로가기
Python/크롤링&스크래핑

[웹스크래핑] Selenium(셀레니움) 기본 코드

by 리미와감자 2023. 1. 30.
# 크롬 드라이버 기본 모듈
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# 크롬 드라이버 자동 업데이트을 위한 모듈
from webdriver_manager.chrome import ChromeDriverManager

# 브라우저 꺼짐 방지 옵션
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)

# 불필요한 에러 메시지 삭제
chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])

# 크롬 드라이버 최신 버전 설정
service = Service(executable_path=ChromeDriverManager().install())



browser = webdriver.Chrome(service=service, options=chrome_options)

# 웹페이지 해당 주소 이동
browser.get("https://www.naver.com")

 

셀레니움이 버전이 업그레이드되면서 그전 버전에 사용했던 명령어들이 실행되지 않았다. 위의 셀레니움 기본 코드를 사용하면 웹브라우저가 실행되지않거나 하는 등의 문제를 해결할 수 있다.

댓글