Created
October 7, 2012 01:02
-
-
Save tfkd/3846720 to your computer and use it in GitHub Desktop.
web scraping with phantomjs
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 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