phantomjs 不等待“满";页面加载 [英] phantomjs not waiting for "full" page load

查看:29
本文介绍了phantomjs 不等待“满";页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PhantomJS v1.4.1 来加载一些网页.我无权访问他们的服务器端,我只是获得指向他们的链接.我使用的是过时版本的 Phantom,因为我需要在该网页上支持 Adob​​e Flash.

I'm using PhantomJS v1.4.1 to load some web pages. I don't have access to their server-side, I just getting links pointing to them. I'm using obsolete version of Phantom because I need to support Adobe Flash on that web pages.

问题是许多网站都在异步加载它们的次要内容,这就是为什么 Phantom 的 onLoadFinished 回调(类似于 HTML 中的 onLoad)在并非所有内容都已加载时过早触发的原因.任何人都可以建议我如何等待网页满载来制作,例如,包含所有动态内容(如广告)的屏幕截图?

The problem is many web-sites are loading their minor content async and that's why Phantom's onLoadFinished callback (analogue for onLoad in HTML) fired too early when not everything still has loaded. Can anyone suggest how can I wait for full load of a webpage to make, for example, a screenshot with all dynamic content like ads?

推荐答案

另一种方法是让 PhantomJS 在页面加载后等待一段时间再进行渲染,就像常规的 rasterize.js 示例,但超时时间更长以允许 JavaScript 完成加载其他资源:

Another approach is to just ask PhantomJS to wait for a bit after the page has loaded before doing the render, as per the regular rasterize.js example, but with a longer timeout to allow the JavaScript to finish loading additional resources:

page.open(address, function (status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
        phantom.exit();
    } else {
        window.setTimeout(function () {
            page.render(output);
            phantom.exit();
        }, 1000); // Change timeout as required to allow sufficient time 
    }
});

这篇关于phantomjs 不等待“满";页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆