我在NODEjs中使用噩梦,欢乐时光和请求的组合,以制作自定义的Web抓取机器人...我使用噩梦js进行了身份验证和过滤器设置,现在我需要像

    request(URL, function(err, response, body){
    if (err) console.error(err);

    var scraping = cheerio.load(body);
    .
    .
    .
    .


但是问题是我不知道如何转发加载的“身体”(噩梦)。我不能使用URL,因为它是动态生成的内容(表),这意味着URL始终是相同的...我试图用它代替URL,但是它不起作用。
有什么建议么?
谢谢

最佳答案

您不需要使用request。实际上,您不应该这样。噩梦本身可以将html数据传递给cheerio。

登录后,进入噩梦中的所需网页,使用evaluate获取html。您可以执行以下操作:

 nightmare
    .viewport(1280, 800)
    .goto(url)
    .wait('#emailselectorId')
    .type('#emailselectorId', 'theEmail\u000d')
    .type('#ap_password', 'thePassword\u000d')
    .click('#signInSubmit')

    //do something in the chain to go to your desired page.
    .evaluate(() => document.querySelector('body').outerHTML)
    .then(function (html) {
        cheerio.load(html);
        // do something
    })
    .catch(function (error) {
    console.error('Error:', error);
    });

07-24 18:16