Skip to content

Instantly share code, notes, and snippets.

@jacoblyles
Created August 5, 2012 00:30
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 jacoblyles/3260825 to your computer and use it in GitHub Desktop.
Save jacoblyles/3260825 to your computer and use it in GitHub Desktop.
Age scraper coursera forum
(function(){
// convert nodelists from querySelector functions into arrays
var posts = Array.prototype.slice.call(
document.body.querySelectorAll('.post_text_container'));
var comments = Array.prototype.slice.call(
document.body.querySelectorAll('.comment_text_container'));
var texts = posts.concat(comments);
var re = /\b\d{2}\b/g;
var nums = [];
texts.forEach(function(item){
var match = item.textContent.match(re);
// exclude posts with more than one potential age for data cleaning
if (match && match.length === 1){
nums = nums.concat(match);
}
});
console.log(nums);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment