Utilities
Select HTML elements and attributes with htmlq
jq-style extraction for HTML, driven by CSS selectors.
overview
What htmlq does
Connect an HTML file and enter a CSS selector such as h1, article a, or meta[name=description]. htmlq writes every matching element to the node's output file.
-t returns text content instead of serialized markup. -a returns one attribute from each selected element, which is useful for links, image sources, and metadata values. The input file is passed with -f.
htmlq parses HTML already present in the workflow. It does not fetch a URL or execute JavaScript. Use browser-fetch or Playwright first when the source still needs to be downloaded or rendered.
source github.com/mgdm/htmlq
use cases
Where htmlq fits
Extract article text
Select a heading or content container and enable -t for plain text.
Collect links
Select anchor elements and set -a to href.
Read metadata
Select a meta element and return its content attribute.
reference
htmlq inputs and flags
| Name | Type | Flag | Description |
|---|---|---|---|
| selector | STRING | --selector | CSS selector to match. |
| input | FILE | --input | HTML input file. |
| text | BOOLEAN | --text | Write text content instead of HTML. |
| attribute | STRING | --attribute | Write one selected attribute value. |
Showing key inputs. htmlq exposes 4 inputs in total.
example
Run htmlq
htmlq -t -f input.html 'h1'Alphaguidance
Choosing htmlq
Use htmlq when an HTML file is already available and a CSS selector identifies the needed content. Use browser-fetch or Playwright when the page still needs retrieval or rendering.
browser-fetch
Fetches pages and saves their HTML before selection.
trafilatura
Extracts main article text without requiring a CSS selector.
jq
Filters JSON rather than HTML.
faq
htmlq questions
related
More Utilities tools
browser-fetch
Headless Chromium render: requested URL, final URL, status, and title next to the page.
cewl
Spider a URL and return a wordlist for password crackers.
csvkit
SQL on one CSV. The table name is the file stem.
dnsgen
Wordlist and mined-word subdomain permutation.
duckdb
In-process SQL on CSV, JSON, and Parquet. No server.
edge-tts
Microsoft Edge neural speech from text or a script file. No API key.
Run htmlq yourself
A small HTML fixture feeds htmlq with selector h1 and -t, returning the heading text.
Facts on this page come from the live Trickest tool library.