I am currently writing a web-application that involves some web-scraping. To help with this, I am employing the help of phantomjs. However, certain (but not all) web pages are returning a status="fail".
Here is the code (note: This is actually written in nodejs using the node-phantom library found here: https://github.com/alexscheelmeyer/node-phantom. While the syntax may be different, the library actually works directly with phantomjs so it shouldn't be doing anything different:
phantom.create(function (err,ph) {
ph.createPage(function (err,page) {
page.onResourceError = function(errorData) {
console.log('Unable to load resource (URL:' + errorData.url + ')');
console.log('Error code: ' + errorData.errorCode + '. Description: ' + errorData.errorString);
};
page.onLoadFinished = function(status) {
console.log('Status: ' + status);
if(status==='success') {
page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', function () {
if(fetch_results) {
//THIS IS WHERE YOU WILL DO RESULTS SHIT
console.log("results page stuff entered");
page.render('phantomjs-test2.png');
ph.exit();
} else {
page.evaluate(function () {
//page evaluate stuff
}, function(err, result) {
console.log("entering here");
page.render('phantomjs-test.png');
if(!err) fetch_results = true;
});
}
});
} else {
console.log(
"Error opening url \"" + page.reason_url
+ "\": " + page.reason
);
console.log("Connection failed.");
ph.exit();
}
}
//page.open("https://www.google.com",function (err,status) {});
page.open("https://www.pavoterservices.state.pa.us/Pages/PollingPlaceInfo.aspx",function (err,status) {});
});
}, {parameters:{'ignore-ssl-errors':'yes'}});
So for page.open with google.com, the page loads succesfully. However, with the other url listed, it returns the following error:
Unable to load resource (URL:https://www.pavoterservices.state.pa.us/Pages/PollingPlaceInfo.aspx); Error code: 2. Description: connection closed; Error opening url "undefined": undefined
Any help as to why google will load but not the url listed would be greatly appreciated!