WEB SCRAPING - 噩梦和请求

问题描述 投票:0回答:1

我在NODEjs中使用梦魇,cheerio和请求的组合,用于制作自定义网络抓取机器人......我使用梦魇js进行身份验证和过滤器设置,现在我需要调用函数

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

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

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

javascript node.js web-scraping nightmare
1个回答
3
投票

你不需要使用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);
    });
© www.soinside.com 2019 - 2024. All rights reserved.