public
Last active

taking phantomjs for a test drive

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// 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();
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.