我需要添加壁虎驱动程序才能在 Azure 上运行无头浏览器作为我网站的一部分,但我需要将壁虎驱动程序添加到 PATH 中(显然我无法在 Python 中手动输入壁虎驱动程序文件的位置?
我知道我必须使用 applicationHost.xdt 文件并将其添加到/home/site 文件夹,但我的 Kudu 页面不允许我添加文件(我可以使用"触摸"创建文件,但我无法编辑它(。
这是我的Kudu页面的样子:https://i.stack.imgur.com/lnbzT.jpg
这是我的应用程序Host.xdt:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.webServer>
<runtime xdt:Transform="InsertIfMissing">
<environmentVariables xdt:Transform="InsertIfMissing">
<add name="geckodriver" value="geckodriverL" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
<add name="PATH" value="%PATH%;%HOME%sitewwwrootcpu" xdt:Locator="Match(name)" xdt:Transform="InsertIfMissing" />
</environmentVariables>
</runtime>
</system.webServer>
</configuration>
这是我从 Django 得到的错误:
WebDriverException at /
Message: 'geckodriverL' executable needs to be in PATH.
Request Method: GET
Request URL: http://site.azurewebsites.net/
Django Version: 2.2.6
Exception Type: WebDriverException
Exception Value:
Message: 'geckodriverL' executable needs to be in PATH.
Exception Location: /antenv/lib/python3.7/site-packages/selenium/webdriver/common/service.py in start, line 83
Python Executable: /opt/python/3.7.4/bin/python3.7
Python Version: 3.7.4
Python Path:
['/opt/python/3.7.4/bin',
'/home/site/wwwroot',
'/antenv/lib/python3.7/site-packages',
'/opt/python/3.7.4/lib/python37.zip',
'/opt/python/3.7.4/lib/python3.7',
'/opt/python/3.7.4/lib/python3.7/lib-dynload',
'/opt/python/3.7.4/lib/python3.7/site-packages']
Server time: Fri, 18 Oct 2019 14:39:59 +0000
据我所知,根据Kudu wiki页面Azure Web App沙箱,由于Win32k.sys(User32/GDI32(限制,您不能在GDI中使用任何包含无头浏览器的内容,例如带有Blink的Chrome和带有Gecko的Firefox。
要修复它,请切换到在 Linux 上使用 Azure VM 或 Azure WebApp(它基于 Docker(。