用 CSS 选择器查询 HTML
htmlq 从 stdin 读取 HTML,用 CSS 选择器提取文本/属性,类似 jq 之于 JSON。适合脚本化抓取/检查页面。
curl -s https://example.com | htmlq 'h1' --text
curl -s https://example.com | htmlq 'a' --attribute href
htmlq 'div.item' < page.html
< file 或管道。--text 只输出文本,--attribute 输出属性;默认输出 HTML 片段。:has() 等支持的语法。合上页面,先回答,再展开对照。
htmlq 从哪里读取 HTML?--text 和 --attribute 有什么区别?htmlq 支持 XPath 吗?< file 传入,不接受文件名参数。--text 输出选中元素的文本;--attribute 输出指定属性的值。xmllint 或其他工具。
小程序版
微信扫码,随时查命令