运行使用C#Phantomjs抢网页快照 [英] Running Phantomjs using C# to grab snapshot of webpage
问题描述
我试图抓住用phantomjs我自己的网站的快照 - 基本上,这是创建的用户提交的内容是preVIEW形象
我已经安装在服务器上phantomjs,并证实,对相应的页面在命令行中运行它工作正常。然而,当我尝试从网站上运行它,它似乎并没有做任何事情。我已经证实,code被调用,那幻象实际上是运行(我监控的流程,可以看到它出现在进程列表当我打电话吧) - 不过,正在生成没有图像<。 / p>
我不知道,我应该寻找弄清楚为什么它不会产生图像 - 有什么建议?有关code块是如下:
字符串参数=/ C rasterize.js http://www.mysite.com/viewcontent.aspx?id=123
字符串映像文件名称= @C:\\的Inetpub \\虚拟主机\\ mysite.com \\的httpdocs \\上传\\ img123.png进程p =新的Process();
p.StartInfo.UseShellExecute = FALSE;
p.StartInfo.RedirectStandardOutput = TRUE;
p.StartInfo.CreateNoWindow = FALSE;
p.StartInfo.FileName = @C:\\ phantomjs.exe
p.StartInfo.Arguments =参数++映像文件名称;p.Start();
字符串输出= p.StandardOutput.ReadToEnd();
p.WaitForExit();
我检查phantomjs在其过程中引发的错误。
您可以从Process.StandardError阅读。
VAR的StartInfo =新的ProcessStartInfo();
//这里其他一些参数
...
startInfo.RedirectStandardError = TRUE;
VAR P =新的Process();
p.StartInfo = StartInfo的;
p.Start();
p.WaitForExit(timeToExit);
//读取错误:
字符串错误= p.StandardError.ReadToEnd();
这会给你发生了什么事的想法。
I'm trying to grab snapshots of my own website using phantomjs - basically, this is to create a "preview image" of user-submitted content.
I've installed phantomjs on the server and have confirmed that running it from the command line against the appropriate pages works fine. However, when I try running it from the website, it does not appear to do anything. I have confirmed that the code is being called, that phantom is actually running (I've monitored the processes, and can see it appear in the process list when I call it) - however, no image is being generated.
I'm not sure where I should be looking to figure out why it won't create the images - any suggestions? The relevant code block is below:
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();
I check the errors that phantomjs throws during its process. You can read them from 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();
It will give you an idea of what happened
这篇关于运行使用C#Phantomjs抢网页快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!