我是 Puppeteer 的新手,我正在尝试从使用同一类的两个 div 中获取 textContent。
<div class="post-item">
<div class="post-item-info">
<span class="post-item-status post-comment"></span>
3
</div>
<div class="post-item-info">
<span class="post-item-status post-vote"></span>
5
</div>
</div>
我期望的结果是返回一个数组 [3,5]。我当前的代码如下。
let postInfo = element.querySelector('.post-item-info');
问题是它只返回第一个。请让我知道该怎么做。
你的选择器应该是这样的const nodes = element.querySelectorAll('.post-item-info');
。然后要访问返回集合中的各个项目,请使用传统的 for 循环,例如
for(let i = 0; i < nodes.length; i++){
const currentNode = nodes[i];
// doStuffWith(currentNode);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)