是否Phantom.js捕获所有AJAX? [英] Does Phantom.js capture all AJAX?

查看:538
本文介绍了是否Phantom.js捕获所有AJAX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有有一吨AJAX的骨干应用程序。 (每个页面加载在5-6阿贾克斯调用的结果),因为我有这些看法中的许多看法和意见内部,

I have a backbone app that has a ton of AJAX. (each page load results in 5-6 ajax calls) because I have many views and internal views within those views,

如果我跑Phantom.js,我能得到最终的HTML结果呢?

if I run Phantom.js, can I get the final html result?

最后的结果是用户看到的我所有的Ajax调用运行后。

Final result is what the user sees after all my ajax calls run.

推荐答案

PhamtonJs是无头的WebKit的JavaScript API。当抓取某个网页,PhatomJs会下载所有家属的请求,如图像,JS,CSS ...它也将执行JS和AJAX调用。
然而,当页面完成加载,而不是当没有挂起的请求onLoaded调用回调函数。所以,你必须使用一个技巧这一点。

PhamtonJs is a headless WebKit with JavaScript API. When crawling a page, PhatomJs will download all dependants requests such as images, js, css... It will also executes JS and ajax calls. However the onLoaded callback is invoked when the page finishes the loading, not when there are no pending requests. So, you have to use a trick for this.

有解决问题的两种方法:

There are two way to solve the problem :


  • 等到东西在你页面(元素),有效地改变。最好的例子就是 waitFor.js

  • 等待几秒钟,直到没有收到请求。

这篇关于是否Phantom.js捕获所有AJAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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