目次

Selenium

主なオプションまとめ

Python About
ヘッドレス –headless ブラウザを立ち上げず実行する
ミュート –mute-audio ミュートにする
サンドボックス –no-sandbox サンドボックスを使用しない
/dev/shm –disable-dev-shm-usage /dev/shmを使用しない
–disable-gpu とりあえず付けとけとか
–disable-web-security
–user-data-dir
–allow-running-insecure-content

サンドボックス

/dev/shm

Exclude the collection

option.add_experimental_option('excludeSwitches', ['enable-logging', 'enable-automation'])
オプション 概要
enable-logging コマンドラインにログが出ない
enable-automation 自動なんちゃらによって保護されています的なやつ無効

ウィンドウ最大化

driver.maximize_window()

スクリーンショット

driver.save_screenshot('test.png')

フルページ

w = driver.execute_script('return document.body.scrollWidth')
h = driver.execute_script('return document.body.scrollHeight')
driver.set_window_size(w, h)

Tips

Googleにログイン

DevToolsActivePort file doesn't exist

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

参照