分類:Python3,Windows10,クロム
日付:2021/11/04
seleniumの使い方を毎回忘れるのでチートシートにしました
環境構築
①クロムのバージョンチェック
メニュー右上の︙アイコンをクリック、→ ヘルプ → googleクロムについて を選ぶ
②ダウンロードのページ
https://chromedriver.chromium.org/downloads
確認したバージョンに合わせてリンク先を選択
③Windows10はchromedriver_win32.zipをダウンロード
④zipを解凍してできた chromedriver.exe をc:\にコピー
このあとPythonのコードで
test.py
driver = webdriver.Chrome("c:\chromedriver")
として使うので c:\ に解凍していますが、ほかのフォルダで使うときは、コードとフォルダ名を合わせればOKです
⑤Python側でseleniumライブラリをインストール
pip install selenium
⑥動作テストはこんな感じ
test.py
from selenium import webdriver
driver = webdriver.Chrome("c:\chromedriver")
driver.get("https://yahoo.com")
driver.close()
driver.quit()
yahooが開いて閉じればインストール成功!