以及如何在邮递员沙箱中声明它?
我需要这样的东西:
var h1Text = window.document.querySelector("h1").innerHTML;
console.log(h1Text);
我也需要这样找到一些东西:
我有很多标签,我需要找到一个确切的标签。我应该使用循环方法来查找我想要的东西还是有更好的方法来获取具有请求属性的元素数据?
假设您使用的是 Postman 应用程序,您希望通过 Cheerio 库加载响应正文,并使用 JavaScript 对其进行解析。
这是我过去用来快速解决我的一个问题的示例:
const html = cheerio(responseBody);
var results = [];
html.find('div[class="AutoGrid-cell min-w-0"] > div').each(function (i, e)
{
results.push({
"Item": e.children[e.children.length-3].children[0].children[0].children[0]["data"],
"Price": e.children[e.children.length-4].children[0].attribs["value"]
})
});