LoginSignup
4
4

More than 3 years have passed since last update.

ChromebookでPythonとSeleniumを使いChromeを自動化しよう

Last updated at Posted at 2020-05-28

ChromebookでSeleniumを使うのに最初少し手こずったのと、
手順についてあまりまとめられているものがなかったのでまとめてみました。

!! point !!

★crostiniからやる場合、debian側にもgoogle-chromeをインストールしなくてはならない。
★chromedriverは’/usr/local/chromedriver/’に設置。

1.google-chromeをインストール(chromebookの最初から入ってるchromeとは別で必要)

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb

2.google-chromeのバージョンを確認

$ google-chrome -version

3.chromedriverはlinux用のものをダウンロード。

先程確認したバージョンに対応したものを入れること。
https://chromedriver.chromium.org/downloads
ここでダウンロードしたものをとりあえずLinuxファイルに突っ込む。
(コマンドで入れてパス指定してもよかったかもしれない。)

4.chromedriverのディレクトリを作成

$ sudo mkdir /usr/local/chromedriver

5.作ったディレクトリにchromedriverを移動

$ sudo mv chromedriver /usr/local/chromedriver

6.権限を付与

$ sudo chmod ugo+x /usr/local/chromedriver/chromedriver

7.後はseleniumが入っていないなら入れる

$ pip install selenium



これでいけるはず。
後は適当にスクレイピングしてみてください!

from selenium import webdriver

driver = webdriver.Chrome('/usr/local/chromedriver/chromedriver')
driver.get(url)
html = driver.page_source.encode('utf-8')

# 適当に処理を入れる

driver.quit()
4
4
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
4
4