在 使用 PhantomJS
的 webpage
模块 打开 weibo.con 页面 有 XMLHttpRequest
资源请求
,PhantomJS
能直接得到 该资源的 返回值吗 (response.body)
黄舟2017-04-17 14:31:08
你可以監聽「檔案收到」後的事件,如果型別是 ajax,那你就用 ajax 呼叫這個 url。
現在不用 phantomjs 寫腳本了,一般用 casperjs,但想法一樣。
程式碼可以參考:
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)
}
})