When the URL 10.44.39.252 is first requested 3 frame src are called. I know this because I managed to call the status through the callback page.onNavigationRequested
var page = require('webpage').create();
var fs = require('fs');
//phantom.addCookie({
// Cisco_DeviceManager : 'value', /* required property */
// SSLPreference : 2, /* required property */
// gettingstarted : 1
//});
console.log("\n:Welcome to my Crawler Scrapper:");
var url = 'http://10.44.39.252/';
page.settings.userName='star';
page.settings.password='----------';
page.customHeaders={'Authorization': 'Basic '+btoa('star:xzsawq4321')};
page.settings.userAgent = 'PMG Web Crawler Bot/1.0';//I even tell it that i'm a web crawler
page.onNavigationRequested = function(url,type,willNavigate, main){
//perhaps one of the most important parts
console.log("\n----------------------------------------------");
console.log("Navigation Request Information:\n")
console.log('Trying to navigate to: ' + url); //where are you going?
console.log('Caused by: ' + type); //request type
console.log('Will it actually navigate: ' + willNavigate);
console.log('Sent from the page\'s main frame: ' + main);
console.log("----------------------------------------------\n");
};
page.onResourceError = function(resourceError){
console.log("\nHold Up, We have Errors!")
console.log("Resource Error Information: \n")
console.log('Resoruce ErrorID:' + resourceError.id + '\nURL:' + resourceError.url);
console.log('Resource Error Code: ' + resourceError.errorCode + '\nDescription: ' + resourceError.errorString);
};
page.onConsoleMessage = function(msg) {
console.log("The Browser Replied:" + msg);
};
//////////////////////////////////////////////////////////////////
page.onLoadStarted = function(){
console.log("Loadng Page...")
};
page.onLoadFinished = function(){
console.log("Loading finished:\n");
};
//////////////////////////////////////////////////////////////////
page.viewportSize = {
width: 1920,
height: 1200
};
var sel = 'button1'; //DOM manipulate, selector
var type = 'click', //action
//webpage.open
page.open(url,function(status){
if(status === "success"){
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() { //jquery syntax has been successfully included
setTimeout(function(){
var t = page.evaluate(function(sel) {
var a = $('title').text();
//console.log(sel);
return a;
},0,sel);
console.log("Title: " + t + "\n\n");
phantom.addCookie({
Cisco_DeviceManager : 'value', /* required property */
SSLPreference : 2, /* required property */
gettingstarted : 1
});
page.open('http://10.44.39.252/xhome.htm', function (status) {
$(document).ready(function(){
console.log("Your Document is Ready:"+ document.title +"\n");
/*ajax assynchronous http request
$.ajax({
async: false,//blocks the ajax call, SYNCHRONOUS ajax Request
url: 'http://10.44.39.252/setup_report.htm?button1=Continue', //blocking javascript request
type: 'GET',
data: {button1: 'Continue'},
success: function (out) {
console.log("REQUEST SENT!\n\n");
console.log(typeof(out));
$('button1').trigger(sel);
console.log($('.homecontent').text);
//$("button1").click(function(){
// $("input").trigger("select");
//});
},
error: function(){
console.log("Nein!");
}
});
*/
});
});
},3000);
setTimeout(function() {
page.render("phantomspecs1.jpg");
console.log("\nNow GTFO!")
phantom.exit();
},20000);
console.log("Wait for the Async...");//prints first!
},0);//closes includejs which doesnt operate in the next open...
}else{
console.log("Connect fail");
phantom.exit();
}
});