Cheerio - 仅从 html 文件中获取文本

问题描述

我想知道是否有办法只从加载到 Cherrio 的 XTML 中获取文本。

const html = cheerio.load(originalHtmlString);

如何只访问内容?无需遍历每个元素。

提前致谢

解决方法

你可以使用

$('body').text()

$.root().text()

但它的格式可能没有你想要的那么好。