【问题标题】:Cheerio - get only text from html fileCheerio - 仅从 html 文件中获取文本
【发布时间】:2021-01-05 12:14:37
【问题描述】:

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

const html = cheerio.load(originalHtmlString);

我怎样才能只访问内容?无需遍历每个元素。

提前致谢

【问题讨论】:

    标签: cheerio


    【解决方案1】:

    你可以使用

    $('body').text()
    

    $.root().text()
    

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

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 2023-02-16
      • 2016-02-15
      • 2023-03-18
      • 2015-10-11
      • 1970-01-01
      • 2023-03-31
      • 2020-08-05
      • 1970-01-01
      相关资源
      最近更新 更多