Skip to content

Instantly share code, notes, and snippets.

@1dolinski
Created February 26, 2014 00:02
Show Gist options
  • Save 1dolinski/9220625 to your computer and use it in GitHub Desktop.
Save 1dolinski/9220625 to your computer and use it in GitHub Desktop.
var cheerio = require('cheerio');
var request = require('request');
arry = []
base_url = "https://weworkremotely.com"
function job_hrefs(i, url, arry, callback) {
return request(url, function(err, res, body) {
var jobs = [];
if (!err && res.statusCode == 200) {
$ = cheerio.load(body);
$('ul li a').each(function() {
var temp = {};
temp.hrefs = $(this).attr('href');
jobs.push(JSON.stringify(temp))
})
arry.push(jobs);
}
})
};
for (var i = 1; i < 8; i++) {
var url = base_url + "/categories/" + i + "/jobs"
job_hrefs(i, url, arry, function() {
console.log(arry);
// this isn't returning
// I think I'm missing something about
// how callback functions work
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment