gpt4 book ai didi

c# - 使用 C# 运行 Phantomjs 抓取网页快照

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

我正在尝试使用 phantomjs 抓取我自己网站的快照 - 基本上,这是为用户提交的内容创建“预览图像”。

我已经在服务器上安装了 phantomjs,并确认从命令行针对适当的页面运行它可以正常工作。但是,当我尝试从网站运行它时,它似乎没有执行任何操作。我已经确认代码正在被调用,幻影实际上正在运行(我已经监视了进程,并且在我调用它时可以看到它出现在进程列表中) - 但是,没有生成图像。

我不确定我应该在哪里寻找弄清楚为什么它不会创建图像 - 有什么建议吗?相关代码块如下:

string arguments = "/c rasterize.js http://www.mysite.com/viewcontent.aspx?id=123";
string imagefilename = @"C:\inetpub\vhosts\mysite.com\httpdocs\Uploads\img123.png";

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.FileName = @"C:\phantomjs.exe";
p.StartInfo.Arguments = arguments + " " + imagefilename;

p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();

最佳答案

我检查了 phantomjs 在其过程中抛出的错误。您可以从 Process.StandardError 中读取它们。

var startInfo = new ProcessStartInfo();
//some other parameters here
...
startInfo.RedirectStandardError = true;
var p = new Process();
p.StartInfo = startInfo;
p.Start();
p.WaitForExit(timeToExit);
//Read the Error:
string error = p.StandardError.ReadToEnd();

它会让你知道发生了什么

关于c# - 使用 C# 运行 Phantomjs 抓取网页快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14048895/

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