Skip to content

Instantly share code, notes, and snippets.

@founddrama
Last active September 28, 2015 20:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save founddrama/1491205 to your computer and use it in GitHub Desktop.
Save founddrama/1491205 to your computer and use it in GitHub Desktop.
taking phantomjs for a test drive
// http://www.phantomjs.org/
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
console.log('[phantomjs] Loading page...');
page.open('http://blog.founddrama.net/', function(status){
if (status !== 'success') {
console.log('could not retrieve!');
} else {
page.evaluate(function(){
console.log('[phantomjs] Querying for post titles...');
var list = Array.prototype.slice.call(document.querySelectorAll('h2 > a[rel="bookmark"]'), 0);
console.log('[phantomjs] ' + list.length + ' post titles:');
list.forEach(function(el){
console.log(' ' + el.innerHTML.replace(/<.*?>/g, ''));
});
});
}
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment