Skip to content

Instantly share code, notes, and snippets.

@kxhitiz
Last active August 29, 2015 13:58
Show Gist options
  • Save kxhitiz/10006751 to your computer and use it in GitHub Desktop.
Save kxhitiz/10006751 to your computer and use it in GitHub Desktop.
phantom js usage example
var page = require('webpage').create(),
system = require('system'),
url = "http://localhost:3000";
page.onConsoleMessage = function(msg) {
console.log(msg);
};
if (system.args.length < 2) {
console.log("Usage: headless_crawl.js [url]");
} else {
url = system.args[1];
}
page.open(url, function(status) {
if (status !== "success") {
console.log("Unable to access network");
} else {
// Execute some DOM inspection within the page context
page.evaluate(function() {
var list = document.querySelectorAll('body');
console.log(list[0].innerText);
});
}
phantom.exit();
});
// Alt
// var page = require('webpage').create();
// var url = 'http://instagram.com/';
// page.open(url, function (status) {
// var js = page.evaluate(function () {
// return document;
// });
// console.log(js.all[0].outerHTML);
// phantom.exit();
// });
// https://github.com/colszowka/phantomjs-gem RUBY GEM
// Usage
// Phantomjs.run('headless_crawl.js', 'http://localhost:3000')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment