본문 바로가기
개발기록/python

[python] Selenium (+ 엣지 브라우저)

by spectrum20 2023. 10. 15.

↓ 크롬브라우저는 아래 링크

[python] Selenium (+ 크롬 브라우저) (tistory.com)

 

[python] Selenium (+ 크롬 브라우저)

Selenium 프레임워크 활용 자동화 매크로를 만들어보았다 *** Selenium 4버전 이상에서는 크롬 드라이버를 따로 설치하지 않아도 된다! 크롬드라이버 설치 크롬 브라우저를 사용할거라 내 컴퓨터의

spectrum20.tistory.com

 

Selenium 프레임워크 활용 자동화 매크로를 만들어보았다

 

엣지 드라이버 설치

내 컴퓨터의 크롬 버전에 맞는 엣지드라이버를 설치해준다

 

엣지 버전 확인은 엣지 브라우저 창 오른쪽 맨 끝 점 세 개 → 설정 → Microsoft Edge 정보에 들어가서 확인할 수 있다

(나는 버전 107.0.1418.62 로 되어있다)

 

아래 사이트에서 내 엣지브라우저 버전에 맞는 엣지드라이버를 설치한다

https://developer.microsoft.com/ko-kr/microsoft-edge/tools/webdriver/

 

Microsoft Edge WebDriver - Microsoft Edge Developer

canary Channel Daily release of our latest features and fixes. Version: 120.0.2160.0: Mac | Mac M1 | x64 | x86 | ARM64

developer.microsoft.com

 

 

코드

  • 옵션 설정
options = webdriver.EdgeOptions()
options.add_experimental_option('excludeSwitches',['enable-logging'])
options.use_chromium = True
options.add_experimental_option('detach',True)

 

  • Edge 실행파일 및 드라이버 경로 설정
options.binary_location = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
s = service.Service(r"C:\Users\Administrator\Desktop\edgedriver_win64\msedgedriver.exe")

(Edge 브라우저 exe 파일의 경로를 옵션에 추가, 위에서 설치한 Edge Driver 파일의 경로를 설정)

 

  • Egde 드라이버 생성
driver = webdriver.Edge(options=options, service = s)
driver.get('https://www.google.com')

 

코드

from selenium import webdriver
from selenium.webdriver.edge import service
from selenium.webdriver.common.keys import Keys

# 옵션 설정
options = webdriver.EdgeOptions()
options.add_experimental_option('excludeSwitches',['enable-logging'])
options.use_chromium = True
options.add_experimental_option("detach", True)

# Edge 파일 위치 설정
options.binary_location = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
s = service.Service(r"C:\Users\Administrator\Desktop\edgedriver_win64\msedgedriver.exe")

# Edge 드라이버 생성
driver = webdriver.Edge(options=options, service = s)
driver.get('https://www.google.com')

 

 

반응형

댓글