23
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Headless Chromeでファイルをダウンロード

Last updated at Posted at 2018-06-08

概要

ChromeをHeadlessで動かすと、ファイルをダウンロードしてくれません。
こちらで議論されていますが、セキュリティの観点からのようです。
https://bugs.chromium.org/p/chromium/issues/detail?id=696481

しかしながらLinuxのコンソールで動かしたいという需要があります。
ここに答えが書いてありますが、ChromeDriver のコマンドを発行することでそれが可能になります。
Downloading with chrome headless and selenium

  • Python 3.6.5
  • Google Chrome バージョン: 67.0.3396.79(Official Build) (64 ビット)
  • ChromeDriver 2.40.565383
driver.command_executor._commands["send_command"] = (
    "POST",
    '/session/$sessionId/chromium/send_command'
)
params = {
    'cmd': 'Page.setDownloadBehavior',
    'params': {
        'behavior': 'allow',
        'downloadPath': download_path
    }
}
driver.execute("send_command", params=params)
23
16
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
23
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?