SuperAPI AI 工具集

html-to-markdown-extracting-tables

数据与分析

查看项目

更新于 10-16 07:18

技能介绍

用途:从 HTML 中提取表格数据,例如价格表、数据网格、规格表。html-to-markdown 会把 <table> 元素解析为两种形态:正文中的内联 GFM Markdown 表格,以及在启用文档结构提取时生成的结构化 tables 数组。

主要能力:content 中的 Markdown 表格为 | col | col | 块,适合 LLM 摄入和人工阅读;结构化 tables 数组的每个条目包含 markdown 字段(预渲染)和 grid 结构化单元格(行 × 列),适合下游代码精确访问单元格。内联 Markdown 表格默认渲染;结构化 tables 需在 CLI 加 --include-structure,Python 用 include_document_structure=True,Node.js 用 includeDocumentStructure: true。

必要用法:提取表格:html-to-markdown --json --include-structure input.html | jq '.tables'。仅提取表格忽略正文:html-to-markdown --json --include-structure --no-content input.html | jq '.tables'。查看表格数量与行列:html-to-markdown --json --include-structure input.html | jq '.tables | to_entries | map({index: .key, rows: .value.grid.rows, cols: .value.grid.cols})'。查看首表 Markdown:html-to-markdown --json --include-structure input.html | jq -r '.tables[0].markdown'。单元格内 <br> 默认转为空格,保留硬换行用 html-to-markdown input.html --br-in-tables。程序化访问时,result.tables 仅在 include_document_structure=True 时填充;Node 的 convert() 直接返回 ConversionResult 对象。

限制:嵌套表格会被展平,内表在父单元格中内联渲染;合并/跨行跨列单元格会保留 row_span 与 col_span,重建布局时需同时检查单元格位置和跨度;畸形表格按尽力解析,可通过 result.warnings 或 --show-warnings 查看非致命问题。完整标志集见 references/cli-reference.md 的 Tables 部分。