backend

[Python, Selenium] Selenium webdriver executable_path deprecated warning 해결

버리야 2022. 1. 9. 01:01
반응형

개발환경

Python version : 3.9

Selenium version : 4.1.0 

Chrome driver verison : Latest stable release: ChromeDriver 97.0.4692.71

 

 

python + selenium을 아래 코드로 작성하니 deprecated warning이 떴다

from selenium import webdriver

driver = webdriver.Chrome(executable_path='/Users/buri/Downloads/chromedriver')
driver.get(url)

 

 

console output: 

DeprecationWarning: 

executable_path has been deprecated, please pass in a Service object

 

 

해결 :

webdriver-manager 설치 하기 :  pip install webdriver-manager 

 

코드 수정

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get(url)

 

console output: 

====== WebDriver manager ======
Current google-chrome version is 97.0.4692
Get LATEST chromedriver version for 97.0.4692 google-chrome
There is no [mac64] chromedriver for browser  in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_mac64.zip
Driver has been saved in cache [/Users/buri/.wdm/drivers/chromedriver/mac64/97.0.4692.71]

참고 : https://stackoverflow.com/questions/64717302/deprecationwarning-executable-path-has-been-deprecated-selenium-python

 

DeprecationWarning: executable_path has been deprecated selenium python

I am using sublime to code python scripts. The following code is for selenium in python to install the driver automatically by using the webdriver_manager package # pip install webdriver-manager from

stackoverflow.com

 

반응형