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

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

问题描述

我正在使用 PhantomJS v1.4.1加载一些网页。我没有访问他们的服务器端,我只是获取链接指向他们。我使用过时的Phantom版本,因为我需要在该网页上支持Adobe 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回调(类似于onLoad在HTML中)太早,当不是一切仍然加载时。任何人都可以建议如何等待网页的完整载入,例如,所有动态内容(如广告)的屏幕截图?

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 
    }
});

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

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