Phantomjs工作但很慢 [英] Phantomjs works but is very slow
问题描述
我正在尝试使用PhantomJS截取网页截图。具体来说,我正在使用从 espn.com 的示例-with-phantomjs /rel =noreferrer>这个示例。我的代码如下所示:
I am trying to take a screenshot of a webpage with PhantomJS. Specifically, I am using the example of capturing espn.com
from this example. My code looks like this:
var page = new WebPage();
page.open('http://www.espn.com', function (status) {
page.render('fb.png');
phantom.exit();
});
然后我用我的终端或命令提示符转到我的PhantomJS目录并运行:
I then go to my PhantomJS directory with either my terminal or command prompt and run:
phantomjs shotty.js
一切都运行良好,但完成输出图像需要6-8秒。这是正常的吗?是否有更快的方法来实现这一目标,以便在一秒或更短的时间内完成?
Everything runs great, however it takes 6-8 seconds to complete the output image. Is that normal? Is there a faster way to accomplish this so that it completes in a second or less?
我使用的是CentOS和Windows 7.两个盒子都有8GB的RAM,3.2 GHz CPU,我在速度网上得到22Mbp / s和1Mbp / s
I am using CentOS and Windows 7. Both boxes have 8GB of RAM, 3.2 GHz CPU, and I'm getting 22Mbp/s down and 1Mbp/s up on speedtest.net
推荐答案
是的,这是正常的。当您尝试渲染时,PhantonJS仍会等待 page.open
事件触发加载
事件以表示已经加载了整个DOM。
Yes this is normal. When you attempt to render, PhantonJS will still wait for the page.open
event to fire the load
event to signify that the entire DOM has been loaded.
看看我在本地加载 espn.com
时会发生什么系统。
DOMContentLoaded完成需要约2秒,然后 ready
事件需要约7秒。
Take a look at what happens when I load espn.com
locally on my system.
It takes ~2 seconds for DOMContentLoaded to finish, and then ~7 seconds for the ready
event to fire.
这篇关于Phantomjs工作但很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!