Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created April 14, 2015 00:25
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 rlemon/acbd7d532c57ad346b8b to your computer and use it in GitHub Desktop.
Save rlemon/acbd7d532c57ad346b8b to your computer and use it in GitHub Desktop.
var request = require('request'),
cheerio = require('cheerio'),
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {
'Content-Type': 'text/html'
});
var data = [];
request('http://stackoverflow.com/election/6', function (error, response, body) {
var $ = cheerio.load(body);
$("tr[id*=post]").each(function (i, el) {
data.push({
username: $(el).find(".user-details a ").text(),
profile: $(el).find(".user-details a").attr("href"),
score: $(el).find(".vote-count-post").text()
});
});
res.end(JSON.stringify(data));
});
}).listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment