首页 > 解决方案 > 带有cheerio选择器的Nightmarejs返回所有DOM而不是选定元素

问题描述

在将 nightmarejs 与 Cheerio 配对时遇到了一些问题。尝试将生成的 document.body.innerHTML 从评估传递给cheerio,就像这样

           ...
var title = yield nightmare.goto(urls[i])
                .wait('.result-title')            
                .evaluate(() => document.body.innerHTML)
                .then(function (html) {
                    const $ = cheerio.load(html);
                   ...

但是在调用 console.log($('.address-text')); 我看到了一个永无止境的 DOM 结构。如此屏幕截图所示,这种情况已经持续了很长时间

在此处输入图像描述

标签: node.jscheerionightmare

解决方案


推荐阅读