Selenium Chromedriver アップデート

PC

PythonでのSeleniumのChromedriverの件です。

昨日までサクサク動いていたプログラムが急に動かなくなったぞ?

えーと、
「selenium this version of chromedriver only supports~」

そうか、またChromeのバージョンアップか。
ということで、ドライバーをアップデートするわけですが、そのやり方については以前触れました。

でも、いい加減面倒になってくるんですね。
自動でやってくれないかなー、と。

そうしたら、同じように考える人はいるようです。
毎回プログラムの起動時に、対応しているChromedriverかどうかチェックしてくれて、対応していなかったらアップデートしておいてくれるライブラリがありました。

webdriver_manager

というものですが、普通にpipでインストールできます。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
pip install webdriver-manager
pip install webdriver-manager
pip install webdriver-manager

あとは、ブラウザを立ち上げるプログラムを少し書き換えるだけです。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.chrome import ChromeDriverManager

を冒頭に追加して、

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
driver = webdriver.Chrome()
driver = webdriver.Chrome()
driver = webdriver.Chrome()

だったところを

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
driver = webdriver.Chrome(ChromeDriverManager().install())
driver = webdriver.Chrome(ChromeDriverManager().install())
driver = webdriver.Chrome(ChromeDriverManager().install())

に変えるだけです。
これで手動アップデートとはおさらば。
一つ難点があるとすれば、ブラウザが立ち上がるたびに、

[WDM] – Current google-chrome version is 89.0.4389
[WDM] – Get LATEST driver version for 89.0.4389
[WDM] – Driver [/Users/*****/drivers/chromedriver/mac64/89.0.4389.87/chromedriver] found in cache

といった表示がされるので、ちょっとウザいということくらいでしょうか。

Selenium本

Hands-On Web Scraping with Python Perform advanced scraping operations using various Python librarie
Hands-On Web Scraping with Python Perform advanced scraping operations using various Python librarie 4,304円(税込)【送料込】

楽天Kobo電子書籍ストア

<p><b>Collect and scrape different complexities of data from the modern Web using the latest tools,

Test-Driven Development with Python Obey the Testing Goat: Using Django, Selenium, and JavaScript【電子
Test-Driven Development with Python Obey the Testing Goat: Using Django, Selenium, and JavaScript【電子 3,529円(税込)【送料込】

楽天Kobo電子書籍ストア

<p>By taking you through the development of a real web application from beginning to end, the second

Selenium自?化??完全指南:基于Python【電子書籍】
Selenium自?化??完全指南:基于Python【電子書籍】 7,020円(税込)【送料込】

楽天Kobo電子書籍ストア

<p>本?共有19章。第1〜10章介?Selenium IDE、Selenium WebDriver、Selenium Grid、Appium等工具的?用。第11〜16章介?自?化????的??及模式

Python??WebUI自?化????ーーSelenium3/4+unittest/Pytest+GitLab+Jenkins【電子書籍】[ Storm ]
Python??WebUI自?化????ーーSelenium3/4+unittest/Pytest+GitLab+Jenkins【電子書籍】[ Storm ] 7,083円(税込)【送料込】

楽天Kobo電子書籍ストア

<p>本?主要介?如何基于Python使用Selenium、unittest、Pytest、GitLab、Jenkins等工具??Web UI自?化??,以?助?者提升??水平。本?第1章?要介?自?

洋書 Paperback, Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, an
洋書 Paperback, Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, an 15,783円(税込)【送料別】

Glomarket

*** We ship internationally, so do not use a package forwarding service. We cannot ship to a package

楽天ウェブサービスセンター
タイトルとURLをコピーしました