【问题标题】:using selenium+python+chromedriver+headless-chrome under aws lambda, chrome driver not loading在 aws lambda 下使用 selenium+python+chromedriver+headless-chrome,chrome 驱动程序未加载
【发布时间】:2021-02-02 03:42:56
【问题描述】:

我迫切希望 selenium+python+chromedriver+headless-chrome 在 AWS lambda 下工作,下面的代码在 cloud9 中工作,但一旦在 lambda 函数中启动,它就会一直卡在线上:

driver = webdriver.Chrome(CURR_BIN_DIR+"chromedriver", options=chrome_options)

chromedriver 和 headless-chrome 的版本是 87 这是我的代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os,sys
import subprocess
import shutil
import time

CURR_BIN_DIR = os.getcwd() + "/bin/"


def lambda_handler(event, context):
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--headless')
            chrome_options.add_argument('--disable-gpu')
            chrome_options.add_argument('--window-size=1280x1696')
            chrome_options.add_argument('--no-sandbox')
            chrome_options.add_argument('--hide-scrollbars')
            chrome_options.add_argument('--single-process')
            chrome_options.add_argument('--ignore-certificate-errors')
            chrome_options.add_argument('--disable-extensions')
            chrome_options.add_argument('--no-cache')
            chrome_options.add_argument('--user-data-dir=/tmp/user-data')
            chrome_options.add_argument('--data-path=/tmp/data-path')
            chrome_options.add_argument('--homedir=/tmp')
            chrome_options.add_argument('--disk-cache-dir=/tmp/cache-dir')
            chrome_options.binary_location = CURR_BIN_DIR + "headless-chromium"
            driver = webdriver.Chrome(CURR_BIN_DIR+"chromedriver", options=chrome_options)
            driver.get("https://www.divid.fr")
            text_area = driver.find_element_by_id("about").text.strip()
            print(text_area)
            driver.close()
            return text_area

谢谢!

【问题讨论】:

  • 我没有收到任何错误,只是“任务超时”

标签: python selenium aws-lambda selenium-chromedriver


【解决方案1】:

通过安装“旧”版本的 headless-chrome 找到了解决方法

V1.0.0-53: https://github.com/adieuadieu/serverless-chrome/releases/download/v1.0.0-53/stable-headless-chromium-amazonlinux-2017-03.zip

和 chromedriver 2.41 : https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip

但我仍然想知道为什么某些东西适用于 cloud9 (EC2) 而不是 lambda 函数!

【讨论】:

    猜你喜欢
    • 2018-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    • 2020-06-08
    相关资源
    最近更新 更多