Calling the following code in node 4.2.0, it's executed in a node cron job and not via terminal. The site I'm 'requesting' is http://www.milb.com/index.jsp?sid=t402.
module.exports.dynamicRequest = function(url, callback) {
var makeDynamicRequest = function(attempt) {
if (attempt === 4) {
svghost.delPhantom();
return callback(new Error('Phantom had 3 failures'));
}
svghost.getPhantom(function(err, ph) {
if (err) {
console.log(err.stack);
setTimeout(function() {
ph.exit();
svghost.delPhantom();
attempt++;
makeDynamicRequest(attempt);
}, Math.pow(2, attempt) * 300);
} else {
ph.createPage(function(page) {
page.open(url, function(status) {
if (status === 'success') {
page.get('content', function(content) {
ph.exit();
svghost.delPhantom();
callback(null, content);
});
} else {
ph.exit();
svghost.delPhantom();
setTimeout(function() {
attempt++;
makeDynamicRequest(attempt);
}, Math.pow(2, attempt) * 300);
}
});
});
}
});
};
makeDynamicRequest(1);
};
svghost is just a simple phantom wrapper that recursively attempts to create a phantom object until successful. I'm confident svghost is not the issue. This works locally 100% of the time but I'm seeing this error when the cron job runs on our server: phantom stdout: NETWORK_ERR: XMLHttpRequest Exception 101: A network error occurred in synchronous requests.
Here's the stack trace:
phantom stdout: /srv/apps/scraper/node_modules/spoton/node_modules/phantom/shim.js:7608 in send
/srv/apps/scraper/node_modules/spoton/node_modules/phantom/shim.js:7608 in _start
/srv/apps/scraper/node_modules/spoton/node_modules/phantom/shim.js:7635