【问题标题】:Python selenium - How to store file on s3 from firefox downloadPython selenium - 如何从 Firefox 下载将文件存储在 s3 上
【发布时间】:2021-02-04 19:54:26
【问题描述】:

我在 aws lambda 和 firefox 驱动程序上使用 python 3.8 + selenium 包

那么如何在 selenium 中设置 firefox 配置文件的下载位置?

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.downloads.folderList", 2)
profile.set_preference("browser.downloads.manager.showWhenStarting", False)
profile.set_preference("browser.downloads.dir","HOW TO SET S3 PATH HERE")

如果不是,那么实现它的最佳方法是什么

【问题讨论】:

  • firefox 只能使用本地目录,因此您的系统必须将 s3 挂载到文件系统,或者能够访问 s3 资源。您更有可能希望在本地下载,然后将其作为单独的进程上传到 s3。

标签: python-3.x selenium amazon-s3 aws-lambda selenium-firefoxdriver


【解决方案1】:

Selenium 对 AWS 或 S3 一无所知。您可以将文件下载到本地文件系统,然后使用 boto3 上传到 S3。例如:

profile.set_preference("browser.downloads.dir", DOWNLOAD_DIRECTORY)

# when Selenium run is complete, create a gzipped tar file of downloads
tarball = "{0}.tar.gz".format(DOWNLOAD_DIRECTORY)
with tarfile.open(tarball, "w:gz") as f:
    f.add(DOWNLOAD_DIRECTORY)
    client = boto3.client("s3")
    try:
        client.upload_file(tarball, S3_BUCKET, s3_key_name)
    except ClientError as e:
        log.error(e)

【讨论】:

  • 感谢基尔尼非常感谢您的支持
猜你喜欢
  • 2018-12-31
  • 2019-11-25
  • 1970-01-01
  • 2021-02-28
  • 2015-05-20
  • 1970-01-01
  • 2014-04-04
  • 2017-02-16
  • 2013-10-15
相关资源
最近更新 更多