【发布时间】:2022-11-20 00:58:43
【问题描述】:
如何在 cheerio 解析器中只获取文本
const cheerio = require("cheerio");
const axios = require("axios");
const getGPUCheckInfo = (html) => {
const $ = cheerio.load(html);
$("#summary > table > tbody > tr").each((i, element) => {
console.log($(element).find("th").text());
});
};
axios
.get(
"https://www.gpucheck.com/en-usd/gpu/nvidia-geforce-gtx-1050-ti/intel-core-i3-6100-3-70ghz/",
{
headers: {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36",
},
}
)
.then((response) => getGPUCheckInfo(response.data), console.log);
如何在没有其他标签的情况下只获得“综合得分”文本
实际上我有这个文本和标签内的文本
【问题讨论】:
标签: javascript node.js parsing cheerio