Anticipating the page loading error
Since we will soon be dealing with page loading, we should have some capabilities to identify whether or not the page is properly loaded. We can do this by checking the status of the loading of the page using the webpage
object's open
callback.
var system = require('system'); var url = system.args[1]; var page = require('webpage').create(); page.open(url, function(status) { if(status == 'success') { console.log('Page loaded.'); // do more stuff here on the loaded page } else { console.log('Ooops! Problem loading page: ' this.url); phantom.exit(1); } });
The open
method's second parameter is a callback that will be executed after the page loads, with or without an error. The function callback will have a single parameter that will hold the status of the page loading operation. The object is in the string format.
The parameter will have the value 'success'
if the page...