You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just writing to ask if there is a simple way I can accomplish this.
I want to know if I can run a part of a nightmare, then stop and do whatever I like...say start a for loop, and then within that loop start up some more of the nightmare where the nightmare left off. As in, still logged in that is. Then I'd run a little more chunk of nightmare code, and then upon the next iteration begin some more nightmare code....all on the same login.
I'll try and write some psuedo-code to help explain it.
Nightmare = req (nightmare)
var myArray = [.., .., .., ..];
var newArray = [];
var myNM = new Nightmare
//Initial login with my nightmare.
myNM.goto('yahoo.com')
.type('#login', login)
.type('#pass', pass)
.click('#submit')
.run();
//Stop and begin a for loop.
for (i = 0; i < myArray.length; i++) {
//Immediately invoke the previous nightmare and start some more code right where it had left off..
myNM.wait()
.type('#field1', myArray[i])
.click('#checkBtn')
.wait()
//Give back some data...add it to the newArray for later.
.evaluate(func() {
newArray.push(document.querySelector('#result'));
return document.querySelector('#result');
}, func(res) { console.log(res); })
.run()
}
//Print out the contents of the newArray we just built.
console.dir(newArray);
The text was updated successfully, but these errors were encountered:
I actually figured it out on my own, and I am quite proud if I do say so myself.
Please note that I took no actual elements or selectors from Google's site...it's all sort of just made up, but you should get the idea.
So basically all I did here was eliminate the run()'s until the very end after everything. I invoked the myScrape nightmare by name within the for loop on the first nightmare command, and then continued as normal again....then ending that line/command with the semi-colon at the end of the trail, then run() at the end afterward.
var Nightmare = require('nightmare');
var myScrape = new Nightmare()
.goto('http://google.com/account')
.type('#login-id', "joeschmoe.somebody.fancy@gmail.com")
.type('#login-password', "P@ssw0rd")
.click('#sign-in')
.wait();
//Start a loop.
for (i = 0; i < 10; i++) {
myScrape.goto('http://google.com/mail')
.wait()
.screenshot("./screens/google"+i+".jpg");
}
myScrape.run();
I'm just writing to ask if there is a simple way I can accomplish this.
I want to know if I can run a part of a nightmare, then stop and do whatever I like...say start a for loop, and then within that loop start up some more of the nightmare where the nightmare left off. As in, still logged in that is. Then I'd run a little more chunk of nightmare code, and then upon the next iteration begin some more nightmare code....all on the same login.
I'll try and write some psuedo-code to help explain it.
The text was updated successfully, but these errors were encountered: