我已经使用了.NetCore2应用程序,并尝试采取给定网址的屏幕截图。它在本地运行得很好,但在部署到Azure之后,在创建Webdriver时会出现问题。
at OpenQA.Selenium.DriverService..ctor(String servicePath, Int32 port, String driverServiceExecutableName, Uri driverServiceDownloadUrl)
↵ at OpenQA.Selenium.Chrome.ChromeDriverService..ctor(String executablePath, String executableFileName, Int32 port)
↵ at OpenQA.Selenium.Chrome.ChromeDriver..ctor(String chromeDriverDirectory, ChromeOptions options)
↵ at SceenshotApp.Service.Screenshot.TakeScreenshot(String url, Int32 width, Int32 height, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Service\Screenshot.cs:line 21
↵ at SceenshotApp.Controllers.HomeController.TakeScreenshot(String url, Int32 width, Int32 height, Int32 scale, Int32 delay) in D:\Projects\TFT\Bitbucket-Linkury\Website\Tools\ScreenshotAPI\DotNetCore\SceenshotApp\SceenshotApp\Controllers\HomeController.cs:line 51"在我的代码下面
public static string GetScreenshot(string url)
{
ChromeOptions options = new ChromeOptions();
var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
driver.Manage().Window.Size = new System.Drawing.Size(1000, 768);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(100);
driver.Navigate().GoToUrl(url);
driver.Close();
driver.Quit();
return path;
}如何在Azure上使用Chrome驱动程序?
发布于 2019-07-19 15:57:35
正如@IvanYang所说,在Windows的Azure App Service上不支持Selenium,如来自Azure Web App sandbox的下图所示。

原因是Win32k.sys (User32/GDI32) Restrictions

然而,你可以尝试将你的.net核心应用部署到Linux上的Azure app Service,这是基于docker镜像的。
因此,您可以按照快速入门教程Create an ASP.NET Core app in App Service on Linux迁移您当前的应用程序。由于Selenium需要无头chrome,您必须先在docker镜像中安装chromium或chrome或其无头发行版和webdriver,或者先在docker文件中写入,请参考官方文档Tutorial: Build a custom image and run in App Service from a private registry了解。
作为参考,有很多博客对你有帮助,你可以通过谷歌/必应搜索,比如Selenium in Docker with DotNetCore Chrome in Linux and Headless Mode。
希望能有所帮助。
https://stackoverflow.com/questions/57105911
复制相似问题