gpt4 book ai didi

c# - 在 Azure Web 应用程序上运行 Selenium

转载 作者:可可西里 更新时间:2023-11-01 08:25:49 25 4
gpt4 key购买 nike

我有一个 Azure Web 应用程序,当我在 Controller 上调用操作时,我想用它来屏幕抓取网站,就像这样。

var driver = new PhantomJSDriver();
driver.Url = "http://url.com";
driver.Navigate();
var source = driver.PageSource;
var pathElement = driver.FindElementByXPath("//table[@class='someclassname']");

string innerHtml = "";
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
if (js != null)
{
innerHtml = (string)js.ExecuteScript("return arguments[0].innerHTML;", pathElement);
}
return innerHtml;

这在本地运行良好,但是当我上传到我的 Azure Web 应用程序时,出现此错误

Cannot start the driver service on http://localhost:51169/

我认为这与防火墙有关,因为我需要在应用程序首次运行时在我的防火墙设置中批准 PhantomJS。我的问题是如何让它在 Azure 中部署工作?是否有可能,或者我是否需要将其配置为一些单元测试并从 Visual Studio 中运行它?

最佳答案

PhantomJS 目前无法在运行 Azure Web 应用程序的沙箱中运行。查看wiki获取已知当前无法正常工作的列表,以及有关沙箱的许多其他信息。

关于c# - 在 Azure Web 应用程序上运行 Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35683608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com