-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphantom-script.js
38 lines (32 loc) · 1009 Bytes
/
phantom-script.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
/**
* @fileoverview This file is not executed by node, but by phantomjs,
* to capture the content of a url and write to stdout.
*/
var page = require('webpage').create();
var system = require('system');
var lastReceived = new Date().getTime();
var requestCount = 0;
var responseCount = 0;
var requestIds = [];
page.onResourceReceived = function(response) {
if(requestIds.indexOf(response.id) !== -1) {
lastReceived = new Date().getTime();
responseCount++;
requestIds[requestIds.indexOf(response.id)] = null;
}
};
page.onResourceRequested = function(request) {
if(requestIds.indexOf(request.id) === -1) {
requestIds.push(request.id);
requestCount++;
}
};
page.open(system.args[1], function() {});
var checkComplete = function() {
if(new Date().getTime() - lastReceived > 300 && requestCount === responseCount) {
clearInterval(checkCompleteInterval);
console.log(page.content);
phantom.exit();
}
};
var checkCompleteInterval = setInterval(checkComplete, 1);