python chromedriverの自動バージョンアップ対応

追加記事

もう勝手にドライバーバージョンアップしてくれるそうです
daeudaeu.com

過去記事

pip install webdriver-manager

コードをこんな感じにする。
例外でるときあるので対応もしとこう

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
 
try:
    driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
except Exception:  # This will catch any type of Exception
    driver = webdriver.Chrome()

driver.get('https://google.com')

ネタ元

yuki.world