Skip to content

Instantly share code, notes, and snippets.

@tsikov
Created April 16, 2014 08:13
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 tsikov/10830153 to your computer and use it in GitHub Desktop.
Save tsikov/10830153 to your computer and use it in GitHub Desktop.
Сортиране на групи за приятелство по брой депутати.
var Crawler = require("crawler").Crawler;
var cheerio = require("cheerio");
var c = new Crawler({
"callback": function(error, result) {
var fg = [];
$ = cheerio.load(result.body);
$("ul.DataBlock").find('li').each(function(idx, el) {
var ob = {
cou: $(el).find('a')[0].children[0].data.split("- ")[1],
mem: $(el).find('span')[0].children[0].data.match(/\d+/)[0]
}
fg.push(ob);
});
fg.sort(function(a, b) { return b.mem - a.mem });
fg.forEach(function(ob) {
console.log(ob.cou, ob.mem)
});
}
});
c.queue("http://www.parliament.bg/bg/friendshipgroups");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment