I have a promise call that is supposed to do the following:
1) Get a link from completedLinks
2) Use cheerio to load the html into the $, like jQuery.
3) get the title, and other details from the page
4) save those details to the object siteObj
JS:
completedLinks = ["http://www.example.com/1","http://www.example.com/2","http://www.example.com/3"...]
function fetchSiteDetails(arr) {
return arr.reduce(function(promise, link) {
console.log(link);
var siteObj = {};
var $ = cheerio.load(link);
var titles = $("title").text().trim();
var html = $("#content").html().trim();
var mainContent = $(".left-side").html().trim();
var allLinks = $('a');
siteObj.title = titles;
siteObj.html = html;
siteObj.mainContent = mainContent;
siteObj.subPages = [];
allLinks.each(function(i, elem) {
siteObj.subPages.push($(this).attr('href'));
});
return promise;
}, Promise.resolve());
}
fetchSiteDetails(completedLinks).then(function() {
console.log('all done');
});
Right now it is not completing each task before it starts the next, and finishes before it's done anything.