LoginSignup
8
12

More than 3 years have passed since last update.

pipでSelenium&chrome driverのインストール

Last updated at Posted at 2019-06-11

概要

pipでインストールする過程について
chrome driverとchromeのバージョンが合わず以下のようなエラーが出てハマったのでメモ

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 76

解決方法

pipでchrome driverをインストールする際は必ずバージョン管理する
またchromeとバージョンを揃える
ヘルプ>googlechromeについてより確認可能

$pip install chromedriver-binary==75.0.3770.8.0
$pip install selenium

テストコード

上手くインストールできたなら以下のテストコードが動くはず

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_binary
options = Options()
options.binary_location = '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
options.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://www.google.co.jp/')
html = driver.page_source
print(html)
driver.quit()
8
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
12