gpt4 book ai didi

c# - 如何使用asp.net和phantomjs截屏页面返回给客户端

转载 作者:行者123 更新时间:2023-11-30 18:54:52 26 4
gpt4 key购买 nike

我希望能够读取网站的屏幕截图,并且正在尝试使用 phantomjs 和 ASP.NET。

我曾尝试使用 page.render 将屏幕截图保存到文件中。它作为控制台应用程序工作,但当我从 asp.net 处理程序中调用它时却不行。这可能是由于文件权限,因为简单的应用程序(如 hello.js)工作正常。

没关系,我的偏好不是写入文件,而是处理字节并直接从处理程序返回图像。

我有点不知道该怎么做。我注意到一个名为 page.renderBase64 的方法,但不知道如何使用它。

目前我正在使用 IHttpHandler。

这里有一个类似的问题,但是那个人最终放弃了phantomjs。我喜欢它的外观,并希望尽可能继续使用它。 Running Phantomjs using C# to grab snapshot of webpage

最佳答案

根据您最后的评论,您可以在 phantom js 文件中执行以下操作:

var base64image = page.renderBase64('PNG');
system.stdout.write(base64image);

在 C# 中:

    var startInfo = new ProcessStartInfo {
//some other parameters here
...
FileName = pathToExe,
Arguments = String.Format("{0}",someParameters),
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
WorkingDirectory = pdfToolPath
};
var p = new Process();
p.StartInfo = startInfo;
p.Start();
p.WaitForExit(timeToExit);
//Read the Error:
string error = p.StandardError.ReadToEnd();
//Read the Output:
string output = p.StandardOutput.ReadToEnd();

在您的输出 变量中,您可以读取从 phantomJS 返回的 base64,然后使用它执行您计划的操作。

关于c# - 如何使用asp.net和phantomjs截屏页面返回给客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16165755/

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