-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagetitle3.js
45 lines (34 loc) · 843 Bytes
/
pagetitle3.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
var system = require('system');
var args = system.args;
var done = [];
if (system.args.length <= 1) {
console.log('No website specified');
phantom.exit();
}
for (var i = 0; i < args.length - 1; i++) {
done[i] = false;
}
function exitIfDone() {
for (var k = 0; k < args.length - 1; k++) {
if (done[k] == false) {
return;
}
}
phantom.exit();
}
function retrieveOneTitle(url, index) {
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log('Page title is ' + msg);
};
page.open(url, function(status) {
page.evaluate(function() {
console.log(document.title);
});
done[index] = true;
exitIfDone();
});
}
for (var j = 0; j < args.length - 1; j++) {
retrieveOneTitle(args[j + 1], j);
}