In the past, I’ve already mentioned the jc command in an article. As a reminder, jc allows you to transform textual data from commands or scripts into structured data such as JSON.
And today, I’d like to talk to you about htmlq, which uses the same principle of operation as jq, except that we’re working with structured data in HTML. The tool allows you to select and extract elements from an HTML file using CSS selectors.
To make it easier for you, here’s an example of how to retrieve the HTML contained in an element whose class is .post:
curl --silent https://tech2geek.net/ | htmlq '.post'

For example, to output all the links on a page:
curl https://tech2geek.net/ | htmlq --attribute href a
Or to retrieve only a text format (without HTML tags):
curl --silent https://tech2geek.net | htmlq --text .post
This makes it quite easy to do a lot of things without necessarily having to code something to play with XPaths.
Now, to install htmlq, it depends on your OS:
- Linux:
cargo install htmlq
- FreeBSD:
pkg install htmlq
- Homebrew (macOS):
brew install htmlq
- Scoop (Windows):
scoop install htmlq
For all the details, I invite you to read the documentation on GitHub.
And if you'd like to go a step further in supporting us, you can treat us to a virtual coffee ☕️. Thank you for your support ❤️!
We do not support or promote any form of piracy, copyright infringement, or illegal use of software, video content, or digital resources.
Any mention of third-party sites, tools, or platforms is purely for informational purposes. It is the responsibility of each reader to comply with the laws in their country, as well as the terms of use of the services mentioned.
We strongly encourage the use of legal, open-source, or official solutions in a responsible manner.


Comments