forked from victorpoluceno/phantomjs-load
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.js
More file actions
32 lines (30 loc) · 973 Bytes
/
Copy pathload.js
File metadata and controls
32 lines (30 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var page = require('webpage').create(),
t, address;
if (phantom.args.length === 0) {
console.log('Usage: load.js <URL>');
phantom.exit(1);
} else {
t = Date.now();
address = phantom.args[0];
page.onConsoleMessage = function (msg) { console.log(msg); };
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
console.log(status);
} else {
t = Date.now() - t;
console.log('Page title is ' + page.evaluate(function () {
return document.title;
}));
console.log('Loading time ' + t + ' msec');
page.render('images/page_' + Date.now() + '.png')
phantom.exit();
}
});
page.onError = function (msg, trace) {
console.log(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
})
}
}