Last active
August 29, 2015 13:58
-
-
Save kxhitiz/10006751 to your computer and use it in GitHub Desktop.
phantom js usage example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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