离线 · 无上传 · 浏览器本地完成Offline · no uploads · runs in the browser
HTML 转 JSON——离线、表格成对象、不上传HTML to JSON offline — tables become objects, no upload
从保存下来的网页、邮件或富文本里取数据,最省事的结果是一份能喂给程序的 JSON。这条路只认文档里的 `<table>`:首行给出键名,其余每行成为一个对象;取行取格都用「只看这张表自己」的作用域,所以表头用 `<th>` 写的文档不会因为只读 `<td>` 而整列左移,表格套在单元格里也不会把内层的行摊平成外层的数据行。没有表格时会退一步:把 `<pre>` / `<code>` 里的内容当 JSON 解析(那是从代码块救回数据的常用一路),再不行就报错,不返回空结果。整个过程在标签页里完成——解析用 DOMParser,它只解析不执行,页面里指向网络的图片与脚本一概不会被请求。When the data lives in a saved page, an email or a rich-text blob, the useful result is JSON a program can read. This route looks only at the document’s `<table>` elements: the first row supplies the keys and each later row becomes an object. Rows and cells are read with a “this table only” scope, so a page whose header row is written with `<th>` cannot shift every value one column left, and a table nested inside a cell does not have its rows flattened into the outer table’s data. With no table at all it falls back one step and parses the text of a `<pre>` / `<code>` block as JSON — the usual way to rescue data out of a code block — and otherwise reports failure rather than handing back an empty result. None of it reaches the network: DOMParser parses without executing, and images or scripts the page points at are never fetched.
这条链路怎么走How the route runs
HTMLHTML JSONJSON
共 1 步,由扩展的路径搜索自动选出,中间产物不落盘。1 step, chosen by the extension's own path search; intermediate results never touch the disk.
会保留什么What carries over
- 首行给键名、每行一个对象;`<th>` 与 `<td>` 同等对待,用 `<th>` 写表头的规范文档不会因此错位The first row names the keys and each later row becomes an object, with `th` and `td` treated alike, so a properly written header cannot shift the values
- 只看这张表自己:内层表格的行不会混进外层数据行,文档里表格套表格也不会凭空多出记录Only the table’s own rows are read, so a nested table contributes neither rows nor phantom records to the outer one
- 单元格取 `textContent` 并去掉首尾空白:链接与嵌套标记只剩文字,样式与结构不会污染值Cells come from `textContent` with the ends trimmed: links and nested markup leave only words, so styling and structure cannot contaminate values
- 没有表格时读 `<pre>` / `<code>`:一份被包进代码块的 JSON 还能原样救回来With no table, `<pre>` / `<code>` is read: JSON that someone wrapped in a code block can be rescued as it stands
如实说明的限制What it does not do
- 多张表不再是一个数组:两张以上会输出以文档小标题为键的**对象**(标题不足时用 `Sheet2` 这类名字),顺序按文档而不是按语义Several tables are no longer one array: two or more produce an **object** keyed by the document’s headings (falling back to names like `Sheet2`), in document order rather than semantic order
- 列数由首行决定:某行比表头多出的单元格会被丢掉,缺的列不会补键;表头里重复或为空的格子会互相覆盖,跨 `colspan` 的表头只算一格The first row defines the columns: cells beyond it are dropped, short rows do not gain keys, a repeated or empty header overwrites its twin, and a header spanning `colspan` counts once
- 合并区不展开:被 `colspan` / `rowspan` 覆盖的格子不产生值,所以那一行的列会左移(要稳定的列位置,先在源文件里取消合并)Merged ranges are not expanded: cells covered by `colspan` / `rowspan` produce no value, so that row’s columns shift left — unmerge in the source for stable positions
- 值一律是字符串:JSON 里不会有真数字与真日期;`colspan`、`scope`、样式、脚本、表单与图片都不进结果,链接地址也不保留Every value is a string: no real numbers or dates in the JSON; `colspan`, `scope`, styles, scripts, form controls and images leave nothing behind, and link addresses are not kept
- 畸形或空表格不会静默产出 `[]`:解析不出可用记录时报错;空数组、对象数组、混形数组这些情况请按 JSON 转 CSV 那条的 `_value` 规则去看A malformed or empty table does not quietly yield `[]` — it reports failure; for arrays of mixed or scalar shapes, see the `_value` rule on the JSON to CSV route
实操提示Working with it
- 要的是能继续算的表格:取到 JSON 之后走 JSON 转 CSV 或转 Excel;多张表请先逐张转,别让分组对象撞上「只接受数组」那道闸For a table you can compute on: take the JSON on to CSV or Excel, and convert several tables one at a time so the grouped object never meets the “arrays only” gate
- 要的是可读的网页或文档:直接 HTML 转 Word、转 PDF 或转 Markdown,不必先绕 JSONFor something readable: go HTML to Word, to PDF or to Markdown directly instead of routing through JSON
- 只想留一份可复查的原始数据:HTML 转 TXT 会按阅读顺序抽文字,比 JSON 更贴近页面看到的内容To keep the page as it reads: HTML to TXT extracts words in reading order, which stays closer to the page than JSON does
常见问题Questions people actually ask
我的页面里有三张表,会得到什么?My page has three tables — what do I get?
一个对象,而不是数组:键取每张表前面的小标题(没有足够的标题时退到 `Sheet2` 这类名字),值分别是各自的对象数组。要三份彼此独立的数组,就把表分开到三个文件里逐张转。An object rather than an array: the keys come from the headings above each table (falling back to names like `Sheet2` when there are not enough), each holding its own array of objects. For three independent arrays, split them into three files and convert one at a time.
转出来的数字为什么带引号?Why are the numbers quoted?
因为 HTML 单元格里只有文字,这一层不做类型猜测——猜过就把 `00123` 变成 `123`、把 `1/2` 变成日期。需要真数字,请在下游按列自己转(本项目在 CSV / Excel 那几条路上刻意保留原字符)。Because a cell holds words, and this layer guesses no types — guessing is how `00123` becomes `123` and `1/2` becomes a date. Convert per column downstream when you need numbers; the CSV and Excel routes here deliberately keep the file’s own characters.
打开那份 HTML 会加载它引用的图片和脚本吗?Does opening that page fetch the images and scripts it references?
不会。这里读取的是文件自己的字节,解析用 DOMParser(只解析、不执行),扩展也只有 storage 权限、没有 host 权限,因此产物里指向网络的地址同样不会被请求。No. The file’s own bytes are read, parsing goes through DOMParser (which parses without executing), and with the storage permission only and no host permissions, addresses inside the page are never fetched either.
不需要账号,也不需要联网:装好扩展后点图标,在新标签页里打开工作台,文件从磁盘直接选。No account and no network: install the extension, click its icon, and the workbench opens in a new tab reading straight off your disk.
从 Chrome 应用商店安装Install from the Chrome Web Store 安装步骤Install steps GitHub 源码Source on GitHub