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

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

问题描述

我有一个包含大量 AJAX 的主干应用程序.(每个页面加载导致 5-6 次 ajax 调用)因为我在这些视图中有很多视图和内部视图,

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 是一个带有 JavaScript API 的无头 WebKit.在抓取页面时,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天全站免登陆