Add the snapshot endpoint to web.py and have the phantomjs running only load the page's HTML once there are no further pending XHR requests
This commit is contained in:
parent
bde0a29296
commit
738973cf39
4 changed files with 87 additions and 1 deletions
37
util/phantomjs-runner.js
Normal file
37
util/phantomjs-runner.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
var system = require('system');
|
||||
var url = system.args[1] || '';
|
||||
if(url.length > 0) {
|
||||
var page = require('webpage').create();
|
||||
page.open(url, function (status) {
|
||||
if (status == 'success') {
|
||||
var delay, checker = (function() {
|
||||
var html = page.evaluate(function () {
|
||||
var found = document.getElementsByTagName('html')[0].outerHTML || '';
|
||||
if (window.__isLoading && !window.__isLoading()) {
|
||||
return found;
|
||||
}
|
||||
if (found.indexOf('404 Not Found') > 0) {
|
||||
return found;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
if (html) {
|
||||
if (html.indexOf('404 Not Found') > 0) {
|
||||
console.log('Not Found');
|
||||
phantom.exit();
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout(delay);
|
||||
console.log(html);
|
||||
phantom.exit();
|
||||
}
|
||||
});
|
||||
delay = setInterval(checker, 100);
|
||||
} else {
|
||||
console.log('Not Found');
|
||||
phantom.exit();
|
||||
}
|
||||
});
|
||||
}
|
Reference in a new issue