ユーザ用ツール

サイト用ツール


googlecolaboratory_selenium

Colaboratoryでselenium

seleniumのインストール

  • Colaboratoryには基本的なライブラリがインストールされている
  • seleniumはないため、インストールする
!pip install selenium

ChromeDriverのインストール

  • 下記手順でインストールする
  • 最後のコピーは必要なのかわからない
!apt-get update
!apt-get upgrade
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin

プログラム例

  • –no-sandboxがないと動かない
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
 
def main():
 
  # オプションの追加
  option = Options()
 
  option.add_argument('--headless')
 
  option.add_argument('--disable-gpu')
 
  option.add_argument('--mute-audio')
 
  option.add_argument('--no-sandbox')
 
  # option.add_argument('--disable-dev-shm-usage')
 
  # ドライバの設定
  driver = webdriver.Chrome(
      'chromedriver',
      options=option
  )
 
  # 以下処理
 
  # ドライバの破棄
  driver.quit()
 
 
if (__name__ == '__main__'):
 
  main()

googlecolaboratory_selenium.txt · 最終更新: 2021/06/15 22:55 by 127.0.0.1