3
所以維基的例子在這裏有兩個地方有phantom.exit()
。爲什麼我不能在腳本的末尾放置phantom.exit()
?這對我來說沒有太大的意義。PhantomJS 5分鐘Wiki phantom.exit()oddity
var page = require('webpage').create(),
t, address;
if (phantom.args.length === 0) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit(); //Why does this only work if "phantom.exit()" is here,
} else {
t = Date.now();
address = phantom.args[0];
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
t = Date.now() - t;
console.log('Loading time ' + t + ' msec');
}
phantom.exit(); //and here.
});
}
// but not just a single one here?