使用 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