基于 cheerio, 写了个低代码,高效解析轮子

查看 14|回复 0
作者:sead   
低代码,高效而简洁;支持正则表达式,复杂的场景也能很容易提取数据。
  • 支持: Nodejs, TypeScript
  • 依赖: Cheerio, turndown
  • HTML 代码片段可以转 Markdown

    使用 YAML 来配置解析,可高效管理输出 JSON 结构
    以下是最简单的解析形态,有个更复杂 SERP 例子在 git 中可作为学习参考。
    YAML 配置
    tree:
      nodes:
        title:
          selector: title
        body:
          selector: body
          attr: html
          to_markdown: true
    HTML
      
        Cheerio Tree
      
      
        Cheerio Tree
       
          What is Cheerio Tree?
          Cheerio Tree is a powerful utility built on Cheerio, designed for efficient DOM parsing. It enables rapid conversion of HTML data into JSON format. When paired with YAML, it provides an intuitive and streamlined approach to data handling and transformation.
       
      

    输出
    {
      "title":"Cheerio Tree",
      "body":"Cheerio Tree\n============\n\nWhat is Cheerio Tree?\n---------------------\n\n**Cheerio Tree** is a powerful utility built on **Cheerio**, designed for efficient DOM parsing. It enables rapid conversion of HTML data into JSON format. When paired with YAML, it provides an intuitive and streamlined approach to data handling and transformation."
    }
    传输门: https://github.com/serping/cheerio-tree
  • 您需要登录后才可以回帖 登录 | 立即注册

    返回顶部