Command Line

domonic ships a command line tool for working with HTML without writing a script: query a URL, a local file or piped input with CSS or XPath, pull out text or attributes, evaluate pyml, or scaffold a project.

Install

pipx keeps the executable isolated and on your shell path:

brew install pipx
pipx ensurepath
pipx install domonic

pip install domonic also installs the command; pipx just avoids adding domonic to a project environment only for its CLI.

domonic -h          # help
domonic -v          # version

Query a URL

CSS selectors with -q, XPath with -x:

domonic -q https://example.com 'a'
domonic -x https://example.com '//a'

# pin a parser backend
domonic -q https://example.com 'a' --parser selectolax
domonic -x https://example.com '//a' --parser selectolax

Shape the output

Flag

Effect

--text

print each match’s text content instead of its markup

--attr NAME

print the NAME attribute of each match

--first

only the first match

--count

just the number of matches

--parser NAME

parse with a specific backend (see Parser Performance)

domonic -q https://example.com 'h1' --text
domonic -q https://example.com 'a' --attr href
domonic -q https://example.com 'a' --first
domonic -x https://example.com '//a' --count

Local files

domonic --xpath-file ./page.html '//title'
domonic --query-file ./page.html 'a.cta' --parser selectolax

Pipes

Read HTML from stdin by omitting the URL:

curl -s https://example.com | domonic -x '//a' --count
cat page.html | domonic -q 'a.cta' --attr href --parser selectolax

Evaluate pyml

-e renders a domonic expression to markup:

domonic -e 'html(head(), body(h1("hello")))'

Scaffold a project

-p creates a starter project; --server picks the framework:

domonic -p myproject
domonic -p myproject --server fastapi

See Server-Side HTML for what the scaffold gives you.