Chromebook Ideapad DuetでSelenium を動作させるまでのセットアップ内容を備忘録がてら書きます。
なぜやるか
Webスクレイピング をするためです。お試しで使っていたGASでは限界が来たので、もう少し腰を据えて持っている端末からちゃんとやることにします。
複雑なログイン操作などがある場合はSelenium でブラウザ操作を自動化することが有効です。手持ちのChromebook でもやりたいと思い色々調べたところ、一癖あることがわかりました。
詳しくは、先人が解説いただいています。勉強になりますmm
nochitamama.hatenablog.com
なにをするか
Chromebook Ideapad DuetでLinux を立ち上げたまっさらな状態からpipをインストールし、Selenium でChroniumを操作するところまでセットアップします。
動作環境
OS バージョン: 93.0.4577.107
Linux 仮想環境 Linux penguin 5.4.131
手順
sudo apt update && sudo apt upgrade -y
Get:1 https://deb.debian.org/debian buster InRelease [ 122 kB]
Get:2 https://deb.debian.org/debian-security buster/updates InRelease [ 65 .4 kB]
Ign:3 https://storage.googleapis.com/cros-packages/93 buster InRelease
〜略〜
$ sudo apt install -y chromium
Reading package lists... Done
Building dependency tree
Reading state information... Done
〜中略〜
Setting up chromium ( 89 . 0 . 4389 .114-1~deb10u1 ) ...
Processing triggers for desktop-file-utils ( 0 .23-4) ...
Processing triggers for mime-support ( 3 .62 ) ...
Processing triggers for hicolor-icon-theme ( 0 .17-2) ...
Processing triggers for libc-bin ( 2 .28-10) ...
Processing triggers for man-db ( 2 .8 .5-2) ...
Processing triggers for dbus ( 1 .12 .20-0+deb10u1) ...
Processing triggers for fontconfig ( 2 .13 .1-2) ...
$ chromium
[ 4121:4121:1023/001459 .044914:ERROR:sandbox_linux.cc(374 )] InitializeSandbox() called with multiple threads in process gpu-process.
[ 4137:7:1023/001501 .231224:ERROR:command_buffer_proxy_impl.cc(122 )] ContextResult::kTransientFailure: Failed to send GpuChannelMsg_CreateCommandBuffer.
〜ブラウザが立ち上がる〜
Chromium
Chromium を入れることができました。ここからは、Selenium で操作できるためのセットアップが続きます。
URLから chromium -driver[バージョン] deb10u1_arm64.deb をダウンロードします。
https://packages.debian.org/ja/buster/arm64/chromium-driver/download
ダウンロードしたファイルをダブルクリックしてインストールを実行します。
$ chromedriver
Starting ChromeDriver 89 .0 .4389 .114 ( 1ea76e193b4fadb723bfea2a19a66c93a1bc0ca6-refs/branch-heads/ 4389 @{
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
まだ続きます。がんばりましょう。Debian にはデフォルトでpipが入っていないそうなので、インストールします。続けてpipでSelenium のパッケージをインストールします。
$ sudo apt update
Hit:1 https://deb.debian.org/debian buster InRelease
Ign:2 https://storage.googleapis.com/cros-packages/93 buster InRelease
Hit:3 https://storage.googleapis.com/cros-packages/93 buster Release
Get:4 https://deb.debian.org/debian-security buster/updates InRelease [ 65 .4 kB]
Get:6 https://deb.debian.org/debian-security buster/updates/main arm64 Packages [ 303 kB]
Fetched 368 kB in 2s ( 174 kB/s )
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.
$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
〜中略〜
Setting up python3-dev ( 3 . 7 .3-1 ) ...
Processing triggers for man-db ( 2 .8 .5-2) ...
Processing triggers for libc-bin ( 2 .28-10) ...
$ pip3 install selenium
Collecting selenium
Downloading https://files.pythonhosted.org/packages/ad/24 /39cab5fbaf425ff522e1e51cce79f94f10f9523f015d2b2251e43f45e8a2/selenium-4 .0 .0-py3-none-any.whl ( 954kB)
100 % | ████████████████████████████████| 962kB 604kB/s
〜中略〜
pyopenssl 21 .0 .0 has requirement cryptography>= 3 .3 , but you' ll have cryptography 2.6.1 which is incompatible.
Installing collected packages: pyOpenSSL, certifi, idna, urllib3, async-generator, h11, wsproto, attrs, sortedcontainers, outcome, sniffio, trio, trio-websocket, selenium
Successfully installed async-generator-1.10 attrs-21.2.0 certifi-2021.10.8 h11-0.12.0 idna-3.3 outcome-1.1.0 pyOpenSSL-21.0.0 selenium-4.0.0 sniffio-1.2.0 sortedcontainers-2.4.0 trio-0.19.0 trio-websocket-0.9.2 urllib3-1.26.7 wsproto-1.0.0
さぁ、あとは動かすだけです!!
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://google.com/' )
Chromium が起動し、Google の画面が出れば成功です!
ようやくWebスクレイピング を行う下準備ができましたので、これから実装していきます。