2
2

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 3 years have passed since last update.

Python + Selenium Chromedirverとserverless-chromeの相性問題

Posted at

環境

AWS SAM + Python 3.7
AWS LambdaのAmazon Linuxコンテナ上で動作。

動作を確認できた組み合わせ

serverless-chrome 1.0.0.37 + Chromedriver 2.37 + Selenium 3.141.0

chrome_options ではなく oputions にセット。

from selenium import webdriver
from datetime import datetime

CHROME_DRIVER_PATH = "/opt/python/bin/chromedriver"
HEADLESS_CHROMIUM_PATH = "/opt/python/bin/headless-chromium"

def lambda_handler(event, context):
    options = webdriver.ChromeOptions()
    options.binary_location = HEADLESS_CHROMIUM_PATH
    options.add_argument("--headless")
    options.add_argument("--disable-gpu")
    options.add_argument("--window-size=1280x1696")
    options.add_argument("--disable-application-cache")
    options.add_argument("--disable-infobars")
    options.add_argument("--no-sandbox")
    options.add_argument("--hide-scrollbars")
    options.add_argument("--enable-logging")
    options.add_argument("--log-level=0")
    options.add_argument("--single-process")
    options.add_argument("--ignore-certificate-errors")
    options.add_argument("--homedir=/tmp")

    driver = webdriver.Chrome(
        executable_path = CHROME_DRIVER_PATH,
        options = options
    )

    # 以下ブラウザ操作の処理 #

あとAWS SAMはLambdaのメモリーを指定なしにデプロイするとデフォルトで256MBです。
確実に処理がつまってタイムアウトしてしまうので、512MBくらい指定しておきましょう。

参考

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?