var page = require('webpage').create();
page.onAlert = function(msg) {
console.log('ALERT: ' + msg);
phantom.exit();
};
page.onCallback = function(data) {
console.log('CALLBACK: ' + JSON.stringify(data));
};
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.onError = function(msg, trace) {
var msgStack = ['ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
});
}
console.error(msgStack.join('\n'));
};
page.onNavigationRequested = function(url, type, willNavigate, main) {
console.log('Trying to navigate to: ' + url);
/*
console.log('Caused by: ' + type);
console.log('Will actually navigate: ' + willNavigate);
console.log('Sent from the page\'s main frame: ' + main);
*/
}
page.onUrlChanged = function(targetUrl) {
console.log('New URL: ' + targetUrl);
};
page.onLoadFinished = function(status) {
console.log('Status: ' + status);
};
page.open(url, function (status) {
// Check for page load success
if (status !== "success") {
console.log("Unable to access network");
}
else {
console.log('loaded');
console.log(
page.evaluate(function(){
var a1=document.getElementById('a1');
if (a1!=undefined){
//alert(a1.getAttribute('href'));
console.log(a1.getAttribute('href'));
window.location = a1.getAttribute('href');
}
else{
alert('ku ku');
}
/*
setTimeout(function(){
alert('ku ku');
} , 1000);
*/
return ;
})
);
}
//phantom.exit();
});