Reputation: 180
I wand to grab all links from site using Nightmare npm. Then go over each link and grab title and text body. I have this code, it works fine when i pass single link, but when i want loop through result of first function i get an error with emmit.setMaxListeners[]... Thanks for any help.
function getUrls1() {
var n = new Nightmare()
.goto('http://www.example.com/newslist')
.evaluate(function () {
var arr = [];
$('.news4 dd > a').each(function (i) {
arr.push({link: $(this).prop('href')})
})
return arr;
}).run(function (err,result) {
// here i have an array of obj with prop link
// but i need to loop over each link
if(err) throw err;
console.log(result[0].link);
getText(result[0].link);
});
}
function getText(link) {
var n = new Nightmare()
.goto(link)
.evaluate(function () {
return {
title: $('h1.title').text(),
text: $('div.text').text()
};
}).run(function (err,result) {
// here i can write file or do something else
if(err) console.error(err);
console.log(result);
})
}
Upvotes: 0
Views: 828