用 htmlq 按 CSS 选择器提取 HTML

在命令行用 CSS 选择器选中并提取 HTML 节点。

macOSHTML文本解析低风险
运行 curl -s https://example.com | htmlq --text title,打印页面标题。

01命令

命令
$ curl -s https://example.com | htmlq --text title

02作用说明

htmlq 从标准输入读取 HTML,应用 CSS 选择器并输出匹配元素、属性或文本。它在 HTML 领域的角色相当于 jq 之于 JSON,可与 curl 自然组合成管道。

03风险

风险低风险
系统兼容性macOS with Homebrew installed
!注意: 它只解析静态 HTML;由 JavaScript 渲染的内容不会出现。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Homebrew formula: htmlq
    Homebrew · vendor-doc · 2026-09-20
    依据: Uses CSS selectors to extract bits content from HTML files. Packages htmlq, which extracts HTML using CSS selectors like jq for HTML.

最后验证: 2026-09-22 · 分类: 开发者

06相关方案