AWS Lambda 上的 Firefox Selenium:二进制文件不是 Firefox 可执行文件

问题描述 投票:0回答:1

我尝试在 AWS Lambda 上使用 Firefox WebDriver 和 Selenium,使用三个 lambda 层:

  1. 壁虎驱动程序
  2. 蟒蛇硒
  3. firefox 二进制文件 (https://ftp.mozilla.org/pub/firefox/releases/69.0.1/linux-x86_64/en-GB/firefox-69.0.1.tar.bz2)

这是我的代码:

import json
from shutil import copyfile
import os
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary



def webdriver_permissions(origin_path, destiny_path):

   ''' The geckodriver and firefox binaries are set in the lambda
   function through a lambda layer. However, by default these files are saved
   in '/opt' folder and hence they are not executable. This function copy the
   binaries to '/tmp' folder and grant them with executable permissions '''


   copyfile(origin_path, destiny_path)
   os.chmod(destiny_path, 0o775)

def lambda_handler(event, context):

    webdriver_permissions('/opt/geckodriver','/tmp/geckodriver')
    webdriver_permissions('/opt/firefox/firefox','/tmp/firefox')

    options = Options()
    options.headless = True
    options.binary =  FirefoxBinary('/tmp/firefox')


    driver = webdriver.Firefox(
        options=options,
        executable_path="/tmp/geckodriver",
        log_path="/tmp/geckodriver.log"
    )

  url = 'foo'
  driver.get(url)

当我运行代码时,代码的 geckodriver 部分工作正常,但是当我到达二进制选项时,会出现此错误:

"errorMessage": "Message: binary is not a Firefox executable\n"

我几乎尝试了一切:

  • 使用不同版本的firefox
  • 使用文件夹中也存在的名为“firefox-bin”的文件,而不是“firefox”
  • 不将二进制文件更改为
    /tmp

对此有什么建议吗?

python-3.x selenium firefox web-scraping aws-lambda
1个回答
0
投票

将文件改为 zip,而不是 tar

© www.soinside.com 2019 - 2024. All rights reserved.