Created
August 5, 2012 00:30
-
-
Save jacoblyles/3260825 to your computer and use it in GitHub Desktop.
Age scraper coursera forum
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
(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