【发布时间】:2019-01-24 05:06:19
【问题描述】:
我正在尝试使用 Cheerio 进行嵌套的每个循环,选择我的 Cheerio 选择两次。我以这种方式编写代码是因为我想迭代父选择的数量,同时进行二次选择。
我的第二个 each 循环没有找到任何元素。我也尝试过创建一个新的cheerio $$ 构造函数并将 html 输入其中,但这也失败了。
$(selector1).each(function (i, el) {
j++;
// logging html is showing several p elements
console.log($(this).html());
$(this).find('p').each((k, elem) => {
// but this loop is not finding any elements
// $(elem).text() returns null
});
});
【问题讨论】: