# htmlq

> HTML parser that uses CSS selectors to extract content from HTML files, similar to jq for JSON

Stars: 7.6k · Language: Rust · License: MIT · Categories: Data

- Repository: https://github.com/mgdm/htmlq
- Page: https://www.trmn.sh/tools/htmlq

## Install

- Homebrew: `brew install htmlq`
- Cargo: `cargo install htmlq`
- FreeBSD pkg: `pkg install htmlq`

## Overview

htmlq is a command-line HTML parser that applies CSS selectors to extract specific content from HTML documents. It functions as an HTML equivalent to jq, allowing users to query HTML files using familiar CSS selector syntax instead of complex parsing logic.

The tool supports multiple output modes including raw HTML extraction, text-only content, and attribute extraction. Users can target elements by ID, class, or any CSS selector, extract specific attributes like href from links, or retrieve only the text content of selected elements. It also provides options to remove unwanted nodes before output and pretty-print the results.

Common workflows include web scraping with curl, extracting links or text content from web pages, and processing HTML files in shell scripts. The tool reads from stdin by default, making it suitable for command pipelines, and can output to files when needed. It's particularly useful for developers and system administrators who need to parse HTML programmatically without writing custom parsing code.

### Installation

```bash
# via Homebrew
brew install htmlq
```

```bash
# via Cargo
cargo install htmlq
```

```bash
# via FreeBSD pkg
pkg install htmlq
```

![Syntax highlighted output](https://media.trmn.sh/cached/0b823e215ae05832845b107e465af5dab83b9980027d807168392014d408dacd.png)

## Alternatives

- [jnv](https://www.trmn.sh/tools/jnv.md): Interactive terminal JSON viewer and jq filter editor with auto-completion, using the built-in jaq engine; reads files or stdin. (Rust, 6.1k stars)
- [jless](https://www.trmn.sh/tools/jless.md): Command-line JSON viewer with syntax highlighting, collapsible sections, and vim-inspired navigation commands (Rust, 5.5k stars)
- [xsv](https://www.trmn.sh/tools/xsv.md): Command line CSV data manipulation tool for indexing, slicing, analyzing, splitting and joining CSV files (Rust, 10.8k stars)
- [qsv](https://www.trmn.sh/tools/qsv.md): Rust CLI toolkit of composable commands for querying, transforming, validating, joining, and describing CSV, Excel, and other tabular data. (Rust, 3.8k stars)
- [angle-grinder](https://www.trmn.sh/tools/angle-grinder.md): Command-line log analysis tool that parses, filters, and aggregates log data with a pipeline query language and a live-updating terminal UI. (Rust, 3.8k stars)

---

Canonical: https://www.trmn.sh/tools/htmlq
