使用带有异步功能的循环

时间:2019-07-30 23:38:24

标签: javascript nightmare

我正在尝试制作访问多个页面并获取html的代码,但是循环不起作用。

const Nightmare = require('nightmare')
const nightmare = Nightmare({show: true, typeInterval: 1, skipTaskbar:true,
    webPreferences:{
      partition: 'persist:foo'}})


async function login(number) {
    return await nightmare
    .goto('https://www.urionlinejudge.com.br/judge/pt/problems/view/'+number)
    .wait('.website-mode')
    .evaluate(() =>{
        return document.querySelector('.main-content').innerHTML;
    })
    .end()
    .then((data) =>{
        console.log(data);
    })
}


for(let i = 1001; i <= 1003; i++){
    login(i)
}

有人可以帮我解决这个问题吗,我让循环等待每个呼叫并按请求的顺序打印它?

0 个答案:

没有答案