Skip to content

Instantly share code, notes, and snippets.

@jclapp23
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jclapp23/35dd767472bf34d622f4 to your computer and use it in GitHub Desktop.
Save jclapp23/35dd767472bf34d622f4 to your computer and use it in GitHub Desktop.
Phantom JS html scraper
var page = require('webpage').create();
page.onError = function (msg, trace) {
phantom.exit();
};
page.onAlert = function( msg ) {
console.log( msg );
if( msg == "EXIT" ){
phantom.exit();
}
};
page.open(config.url, function(status) {
page.includeJs('https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js', function() {
page.evaluate(function(config){
window.setTimeout(function(){
setInterval(function(){
pullHtmlString(config);
}, 2000);
}, 1);
}, config);
});
});
function pullHtmlString(config){
alert($(config.selector).wrap('<p/>').parent().html());
alert( "EXIT" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment