Last active
August 29, 2015 13:56
-
-
Save alexchantavy/8908556 to your computer and use it in GitHub Desktop.
Searches HN February "Who's Hiring" listings for jobs located in San Francisco and Mountain View using phantom.js.
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
var page = require('webpage').create(); | |
// Listener to display console msgs from within page.evaluate() | |
page.onConsoleMessage = function(msg) { | |
console.log(msg); | |
}; | |
// Open HN | |
page.open('https://news.ycombinator.com/item?id=7162197', function(status) { | |
if (status === 'success') { | |
// Get all the <span.comment>s, search for desired string, and return array | |
var result = page.evaluate(function() { | |
var comments = document.getElementsByClassName('comment'); | |
var matches = []; | |
for (var i = 0; i < comments.length; i++) { | |
var text = (comments[i] && comments[i].hasOwnProperty('textContent'))? comments[i].textContent : ''; | |
// Regex is here | |
if (/San Fran|Bay Area|San Jose|California|Mountain View/i.exec(text) != null) { | |
matches.push({'text': text}); | |
} | |
} | |
return matches; | |
}); | |
result.forEach(function(item) { | |
console.log(item.text + "\n----------------------------\n"); | |
}); | |
} | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment