nightmare icon indicating copy to clipboard operation
nightmare copied to clipboard

Using a loop with nightmarejs

Open rangelp opened this issue 5 years ago • 1 comments

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?

rangelp avatar Jul 26 '19 23:07 rangelp

Have your tried via generator and VO?

Sarmad007 avatar Aug 04 '19 13:08 Sarmad007