在 使用 PhantomJS
的 webpage
模块 打开 weibo.con 页面 有 XMLHttpRequest
资源请求
,PhantomJS
能直接得到 该资源的 返回值吗 (response.body)
黄舟2017-04-17 14:31:08
You can listen to the event after "File Received". If the type is ajax, then you use ajax to call this url.
Now we don’t use phantomjs to write scripts. We usually use casperjs, but the idea is the same.
For code, please refer to:
casper.on('resource.received',function(resource){
if (resource.contentType.indexOf("json") != -1 && resource.stage == "end") {
var data = casper.evaluate(function(url){
// synchronous GET request
return __utils__.sendAJAX(url, "GET");
}, resource.url);
console.log(data)
// do something with data, you might need to JSON.parse(data)
}
})