【发布时间】:2014-10-01 23:19:31
【问题描述】:
我正在尝试在网页上记录不断更新的数据。在 Google Chrome 开发者工具中,我可以看到我的传入数据是通过 AJAX 请求获得的。
当我点击“获取”文本文件时,我可以在 Google Chrome 中看到我想要的数据。我想使用 PhantomJS 接收 AJAX 响应,然后将这些响应保存到文件中。
到目前为止,我有一个程序可以打开我感兴趣的网页的 URL,并可以打印出正在接收的网络流量的概述,但我不知道如何保存实际文件,因为它们进来吧。我该怎么做呢?
到目前为止的代码:
var page = require('webpage').create();
var url = "www.site_of_interest.com";
page.onResourceRequested = function(request) {
console.log('Request ' + JSON.stringify(request, undefined, 4));
};
page.onResourceReceived = function(response) {
console.log('Receive ' + JSON.stringify(response, undefined, 4));
};
page.open(url);
【问题讨论】:
-
How can I catch and process the data from the XHR responses using casperjs? 的可能副本。虽然这个问题是关于 CasperJS 的,但大部分代码都可以直接转移到普通的 PhantomJS。
-
感谢您的回复,是的,看起来答案可能在另一个问题中。我去看看。
标签: javascript ajax phantomjs