I'm attempting to scrape dynamic paging websites with Nightmare / Electron. I don't see a way to perform a do... until with nightmare functions OR a way to chain evaluate calls with logic.
Here's a simple code example that merely Googles a phrase and returns the result hrefs from page 1. I'd like this code to continue for each page in the results.
var Nightmare = require('nightmare');
var vo = require('vo');
vo(function* () {
var nightmare = Nightmare({ show: true });
var links = yield nightmare
.goto('http://www.google.com')
.wait('input[title="Search"]')
.click('input[title="Search"]')
.type('input[title="Search"]', 'Anequim Project')
.click('input[name="btnK"]')
.wait(600)
.evaluate(function(){
var linkArray = [];
var links = document.querySelectorAll('h3.r a');
for (var i = 0; i < links.length; ++i) {
linkArray.push(links[i].getAttribute('href'));
}
return linkArray;
});
yield nightmare.end();
return links;
})(function (err, result) {
if (err) return console.log(err);
console.log(result);
});