Commit ef644f30 authored by yPhil's avatar yPhil

Promises

parent abdae87c
const cheerio = require('cheerio'),
rp = require('request-promise-native');
const options = {
method: 'GET',
uri: 'https://yphil.bitbucket.io/'
};
module.exports = function (u) {
return rp(u)
.then(function (body) {
console.log('ok: (%s)');
module.exports = function (u, callback) {
return rp(u).then(function (body) {
const $ = cheerio.load(body);
const $ = cheerio.load(body);
if ($('a').length > 0) {
$('a').each(function() {
if ($(this).attr('href')) {
if ($(this).attr('title'))
console.log('$(this).attr("href"): (%s)', $(this).attr('title'));
// console.log("got: "
// + body);
} else {
console.log('nothing: (%s)');
}
});
}
if ($('a').length > 0) {
$('a').each(function() {
if ($(this).attr('href')) {
if ($(this).attr('title'))
callback($(this).attr('title'));
// console.log("got: "
// + body);
} else {
console.log('nothing: (%s)');
}
});
}
})
.catch(function (err) {
// POST failed...
console.log("ERROR: " + err);
});
}).catch(function (err) {
// POST failed...
console.log("ERROR: " + err);
return err;
});
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment