LoginSignup
11
20

More than 3 years have passed since last update.

CentOS7でselenium、Chrome Web Driveのインストール方法

Last updated at Posted at 2018-05-13

Cent OS6ではうまく行かなかったのでCent OS7での設定になります。

chromeをインストールする

vim /etc/yum.repos.d/google.chrome.repo

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

あとはyumでインストール

yum update
yum install google-chrome-stable
sudo yum install -y libOSMesa google-noto-cjk-fonts

libOSMesaはクラッシュ防止
google-noto-cjk-fontsはフォント

seleniumをインストールする

centOSの場合はpyvirtualdisplayも入れる

pip install selenium
sudo pip install pyvirtualdisplay

pipがない場合は入れる

yum -y install python-devel
yum -y update
yum -y install python-pip

これでセットアップ完了

エラーと対処法

途中で発生したエラーとその対処法です

selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

which chromedriver
でパスを見つけて、
browser = webdriver.Chrome(executable_path='Chromedriverがあるパス')
でパスを指定してあげる

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally

chromedriverのバージョンが古くないか確認
yum update
参考:
https://sites.google.com/a/chromium.org/chromedriver/downloads

selenium.common.exceptions.WebDriverException: Message: chrome not reachable

このメッセージが出る場合はchromeのプロセスだらけになっている可能性があるので

ps aux | grep chrome

で確認

killall chrome
killall chromedriver

コマンドでプロセスを終了する
また、webdriverを動かしているコードにquit()を書いて終わらせる。close()ではプロセスは終了しないので注意。

11
20
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
11
20