Skip to content

Instantly share code, notes, and snippets.

@tfkd
Created October 7, 2012 01:02
Show Gist options
  • Save tfkd/3846720 to your computer and use it in GitHub Desktop.
Save tfkd/3846720 to your computer and use it in GitHub Desktop.
web scraping with phantomjs
var address = ‘http://lantis-net.com/’;
var page = require(‘webpage’).create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open(address, function(status) {
if (status !== “success”) {
console.log(“Unable to access network”);
}
else {
var exitCode = page.evaluate(function() {
var titles = document.body.querySelectorAll(‘.titles’);
for (i = 0; i < titles.length; ++i) {
console.log(titles[i].querySelector(‘a’).innerText);
}
});
}
phantom.exit(exitCode);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment