Skip to content

Instantly share code, notes, and snippets.

@DukeBaird
Last active April 29, 2024 19:17
Show Gist options
  • Save DukeBaird/70c639483aedc4a0133d to your computer and use it in GitHub Desktop.
Save DukeBaird/70c639483aedc4a0133d to your computer and use it in GitHub Desktop.
PhantomJS
var page = require('webpage').create();
var args = require('system').args;
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.onConsoleMessage = function(msg) {
console.log("Browser Console: " + msg);
};
page.onError = function(msg, trace) {
console.log(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
});
}
page.open(url, function(status) {
//do stuff
//Insert data into page
page.evaluate(function(foo, bar) {
//on the page here
}, arg1, arg2);
//Get data from page
var output = page.evaluate(function() {
//do stuff here
return output
});
console.log(output);
}
//page.onLoadFinished = function(status) { // onLoadFinished is overwritten by page.open({})
//console.log('Status: ' + status);
// Do other things here...
//phantom.exit();
//};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment