Phantomjs stops loading full page
I am using PhantomJS 1.9.7 on Debian to parse page content. For some reason, it stops loading the page on any resource loading failure. For example, if it cannot load the .js file, it ends up with a "fail" status. So I get
FAIL to load address: xxxx caused by canceled operation
in page.open()
the state handler.
How can I make PhantomJS load other resources even if some of them cannot be loaded?
source to share
It is possible that SSL is the culprit. You can try various command line options to fix the boot error, for example:
--ignore-ssl-errors=true
--web-security=false
If you know a resource that isn't loading every time, you can explicitly stop loading by listening to the onResourceRequested
event :
page.onResourceRequested = function(requestData, networkRequest){
if (requestData.url.indexOf("yourScript.js") !== -1) {
networkRequest.abort();
}
};
You can also see what kind of error: onResourceError
.
source to share
You can find resources that are failing by typing an error on the console.
page.onResourceError = function(resourceError) {
console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
};
And that should print something like
Unable to load resource (#19URL:http://www.google.com)
Error code: 5. Description: Operation canceled
source to share