如何解决HTMLElement.querySelector() 使用cheerio
使用 vanilla JavaScript,您可以编写
const box = document.querySelector(".box");
const button = box.querySelector(".button");
Cheerio 怎么样? 我想做类似的事情:
const box = $(".box");
const button = box.$(".button")
我之所以这么问是因为我必须遍历元素,然后在该元素中找到一个锚标记:
const $ = cheerio.load(stdout)
const boxes = $(".box").map((i,element) => element)
boxes.each((i,element) => ?? maybe element.querySelector("a") )
解决方法
如果您不想使用 descendant combinator
,您可以使用 find:
const button = box.find("button");
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。