我正在尝试使用phantomjs抓取我自己网站的快照--基本上,这是为了创建用户提交内容的“预览图像”。
我已经在服务器上安装了phantomjs,并且已经确认从命令行针对相应的页面运行它工作得很好。但是,当我尝试从网站上运行它时,它似乎没有任何作用。我已经确认代码正在被调用,phantom实际上正在运行(我已经监控了进程,当我调用它时,可以看到它出现在进程列表中)-但是,没有生成任何图像。
我不确定我应该在哪里找出为什么它不能创建图像-有什么建议吗?相关代码块如下:
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();发布于 2013-04-28 16:01:00
我检查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();它会让你知道发生了什么事
发布于 2015-04-05 20:15:25
从C#代码执行phantomjs的最简单方法是使用像NReco.PhantomJS这样的包装器。以下示例说明了如何将其用于rasterize.js:
var phantomJS = new PhantomJS();
phantomJS.Run( "rasterize.js", new[] { "https://www.google.com", outFile} );Wrapper API具有针对标准输出和标准错误的事件;它还可以提供来自C#流的输入,并将标准输出结果读取到C#流中。
https://stackoverflow.com/questions/14048895
复制相似问题