0

Google Colaboratory上でSeleniumを動かしたいので、

  • Google Chromeの最新版
  • ChromeDriverの最新版

をそれぞれインストールしたいです。
しかし、実行してもエラーが出現します。

前提条件

  • 開発環境はGoogle Colaboratory
  • Seleniumでスクレイピングをしたい。

期待値

  • Google Chromeの最新版とChromeDriverの最新版のインストールを成功させる。
  • 上記二つのバージョンを一致させる。

再現手順

インストール時のコマンド
%%shell

sudo apt -y update && sudo apt -y upgrade
sudo apt install -y wget curl unzip

# Google Chromeの依存関係をインストール
sudo apt install libu2f-udev libvulkan1

# ChromeをDL&インストール
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb

# ChromeDriverをDL&インストール
wget -N https://chromedriver.storage.googleapis.com/99.0.4844.84/chromedriver_linux64.zipp -P /tmp/
unzip -o /tmp/chromedriver_linux64.zip -d /tmp/
chmod +x /tmp/chromedriver
mv /tmp/chromedriver /usr/local/bin/chromedriver
実行結果
前略

E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
wget is already the newest version (1.21.2-2ubuntu1).
curl is already the newest version (7.81.0-1ubuntu1.13).
unzip is already the newest version (6.0-26ubuntu3.1).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 google-chrome-stable : Depends: libu2f-udev but it is not going to be installed
                        Depends: libvulkan1 but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 libu2f-udev : Depends: udev (>= 244) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
--2023-09-24 13:29:01--  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Resolving dl.google.com (dl.google.com)... 142.250.99.136, 142.250.99.93, 142.250.99.190, ...
Connecting to dl.google.com (dl.google.com)|142.250.99.136|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 103481376 (99M) [application/x-debian-package]
Saving to: ‘google-chrome-stable_current_amd64.deb.2’

中略

dpkg: dependency problems prevent configuration of google-chrome-stable:
 google-chrome-stable depends on libu2f-udev; however:
  Package libu2f-udev is not installed.
 google-chrome-stable depends on libvulkan1; however:
  Package libvulkan1 is not installed.

dpkg: error processing package google-chrome-stable (--install):
 dependency problems - leaving unconfigured
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
 google-chrome-stable
--2023-09-24 13:29:15--  https://chromedriver.storage.googleapis.com/99.0.4844.84/chromedriver_linux64.zipp
Resolving chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)... 74.125.135.207, 74.125.195.207, 172.253.117.207, ...
Connecting to chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)|74.125.135.207|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2023-09-24 13:29:15 ERROR 404: Not Found.

中略

unzip:  cannot find or open /tmp/chromedriver_linux64.zip, /tmp/chromedriver_linux64.zip.zip or /tmp/chromedriver_linux64.zip.ZIP.
chmod: cannot access '/tmp/chromedriver': No such file or directory
mv: cannot stat '/tmp/chromedriver': No such file or directory

中略

CalledProcessError                        Traceback (most recent call last)

中略

CalledProcessError: Command '
実行したコマンド
' returned non-zero exit status 1.

マルチポスト

teratailにも同じ質問を投稿しています。

4

1 件の回答 1

0

以下で、Google Colaboratory上で、動作しました。
いかがでしょうか?

◇インストール方法

# Seleniumのインストール

!wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
!dpkg -i google-chrome-stable_current_amd64.deb
!rm google-chrome-stable_current_amd64.deb
!apt install -y chromium-chromedriver

!pip3 install --upgrade selenium
!pip3 install --upgrade webdriver-manager

◇実行

# Seleniumの実行

from selenium.webdriver.chrome.service import Service as ChromeService
from selenium import webdriver
from bs4 import BeautifulSoup
from webdriver_manager.chrome import ChromeDriverManager

service = ChromeService(ChromeDriverManager().install())
options = webdriver.ChromeOptions()
options.add_argument('--disable-gpu')
options.add_argument('--lang=ja-JP')
options.add_argument('--incognito')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(service=service, options=options)

driver.get('https://google.com')
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')

# 出力
element_list = filter(lambda x: len(x) > 0, soup.text.split(' '))
for element in element_list:
    print(element)
1
  • chromium-chromedriverとchromedriverの違いが知りたいです。
    – kamome_run
    Commented 2023年9月29日 11:25

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。