首页 > 解决方案 > 在没有 Docker 的情况下使用 apt-get 在 Azure Functions 中安装依赖项

问题描述

我正在尝试将 Azure Functions 与 Python 一起使用,并使用带有 Firefox 的 Selenium 来抓取网页。对于将要使用的方式,使用消费计划更实用(也更便宜),这意味着我不能使用 Docker 容器。

到目前为止,我已经能够成功地包含和路径 Firefox 的二进制文件以及geckodriver二进制文件。我收到以下错误:

1571952497758   mozrunner::runner   INFO    Running command: "/home/site/wwwroot/SharedCode/bin/firefox/firefox" "-marionette" "--headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileFyNhwV"
XPCOMGlueLoad error for file /home/site/wwwroot/SharedCode/bin/firefox/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.

我的印象是 Firefox/Selenium 在无头模式下运行时不需要 GTK(它是):

webdriver_options = selenium.webdriver.firefox.options.Options()
webdriver_options.binary_location = str( (pathlib.Path(__file__).parent / "../bin/firefox/firefox").resolve() )
webdriver_options.add_argument("--headless")

webdriver = selenium.webdriver.Firefox(executable_path=str( (pathlib.Path(__file__).parent / "../bin/geckodriver").resolve() ), firefox_options=webdriver_options)

这可以通过安装 GTK3 来解决。有没有办法apt-get在没有 Docker 的 Azure Functions App 上安装包?

标签: pythonseleniumfirefoxazure-functions

解决方案


您将无法在 Azure Functions 上运行 Selenium。它在 App Service 容器中运行,该容器是一个安全环境,具有不支持 GDI 或安装包的限制,因为这将使其成为 serverfull 而不是 serverless。由于不使用自定义图像,因此不支持 apt-get。

建议是退出消费计划或转移到低层 BS 系列虚拟机。

底部的此链接显示 selenium 不受支持。

https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#unsupported-frameworks


推荐阅读