Last active
September 28, 2015 20:18
-
-
Save founddrama/1491205 to your computer and use it in GitHub Desktop.
taking phantomjs for a test drive
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
// 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