I'm trying to navigate through pages of an online dictionary. Here is my code:
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true });
var links = [];
function goToLink(linkName){
nightmare
.goto(linkName)
.evaluate( () => {
var href = document.querySelector("span.next a").href;
links.push(href)
return href;
})
.then((href) => {
goToLink(href);
})
.catch((error) => {
console.error('Error:', error);
});
}
goToLink("http://lexicon.quranic-research.net/data/01_a/000_!.html");
I'm getting Error: links is not defined. Links is clearly defined at var links = []; but the inner function doesn't know about it. What is going on here?
evaluatestringifies the argument and evals it ina different context. Edit: see github.com/segmentio/nightmare/issues/89