Last active
August 29, 2015 14:18
-
-
Save jclapp23/35dd767472bf34d622f4 to your computer and use it in GitHub Desktop.
Phantom JS html scraper
This file contains 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 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