nightmare
nightmare copied to clipboard
Using a loop with nightmarejs
I am trying to call multiple instances through a loop, but he nightmare "loses" the target.
`const Nightmare = require('nightmare') const nightmare = Nightmare({show: true, typeInterval: 1, skipTaskbar:true, webPreferences:{ partition: 'persist:foo'}})
class URI {
URL = 'https://www.urionlinejudge.com.br/judge/pt/login'
PAGE = 'https://www.urionlinejudge.com.br/judge/pt/problems/view/'
USER = 'login'
PASS = 'senha'
COOKIE: any
constructor() {}
async login() {
return nightmare
.goto(this.URL)
.type('#email', this.USER)
.type('#password', this.PASS)
.click('#remember-me')
.type('#password', '\u000d')
.wait('#q')
.cookies.get()
.then((cookie) => {
this.COOKIE = cookie;
}).catch((er) =>{
//console.log('Já to logado');
})
}
async problemExtract(number) {
await nightmare.wait('.website-mode')
.goto(this.PAGE+number)
.wait('.website-mode')
//.click('#place .place-view')
.evaluate(() => {
return document.querySelector('#place').innerHTML;
})
.then((data) => {
data = data.split('<a href="');
data = data[1].split('"');
console.log(data[1]);
//nightmare.end();
}).catch(async () => {
await this.login();
this.problemExtract(number);
})
}
} const r = new URI();
for(let i = 1001; i < 1003; i++) r.problemExtract(i); `
This code returns
target= target=
Could someone help me how to call multiple instances and they return correctly?
Have your tried via generator and VO?