Quantcast
Channel: 万维网黑客 » phantomjs
Viewing all articles
Browse latest Browse all 10

phantomjs 资源请求开始 结束回调函数

$
0
0
var page = require('webpage').create();
var system = require('system');
var url = '';

if(system.args.length === 1){
    console.log('Usage: app.js <some URL>');
    phantom.exit(1);
}else{
    url = system.args[1];

    page.onResourceRequested = function(req){
        console.log('requested: ' + JSON.stringify(req, undefined, 4));
    }

    page.onResourceReceived = function(res){
        console.log('received: ' + JSON.stringify(res, undefined, 4));
    }    

    page.open(url,function(status){
        if(status !== 'success'){
            console.log('Failed to load the url');
        }
        phantom.exit();
    });
}

 


Viewing all articles
Browse latest Browse all 10

Trending Articles