# pup

> Command line HTML processing tool using CSS selectors to filter and extract data from HTML documents

Stars: 8.4k · Language: Go · License: MIT · Categories: Data

- Repository: https://github.com/ericchiang/pup
- Page: https://www.trmn.sh/tools/pup

## Install

- Go: `go get github.com/ericchiang/pup`
- Homebrew: `brew install https://raw.githubusercontent.com/EricChiang/pup/master/pup.rb`

## Overview

pup is a command line HTML processor that reads HTML from stdin and filters content using CSS selectors. Inspired by jq, it provides a terminal-based approach to parsing and extracting data from HTML documents. The tool supports standard CSS selectors including class, ID, element, attribute, and pseudo-class selectors, along with combinators like `+`, `>`, and `,` for complex queries.

The tool offers multiple output formats through display functions. The `text{}` function extracts plain text content, `attr{key}` retrieves attribute values, and `json{}` converts HTML elements to JSON format with configurable indentation. pup automatically cleans and indents malformed HTML, making it useful for both data extraction and HTML formatting tasks.

pup integrates well with standard Unix tools and web scraping workflows. Common use cases include extracting links and titles from web pages, parsing structured data from HTML documents, and converting HTML content to JSON for further processing. The tool supports most CSS3 selectors including nth-child selectors, :contains(), :empty, and custom selectors like :parent-of(). Developers and data analysts working with HTML content from APIs, web scraping, or document processing will find pup particularly useful for command-line HTML manipulation tasks.

### Installation

```bash
# via Go
go get github.com/ericchiang/pup
```

```bash
# via Homebrew
brew install https://raw.githubusercontent.com/EricChiang/pup/master/pup.rb
```

## Alternatives

- [dasel](https://www.trmn.sh/tools/dasel.md): Command-line tool for querying, modifying, and transforming structured data files (JSON, YAML, TOML, XML, CSV) (Go, 8.1k stars)
- [jid](https://www.trmn.sh/tools/jid.md): Interactive JSON explorer that takes piped input and lets you drill down with dot-path or JMESPath queries, with tab completion and suggestions. (Go, 7.2k stars)
- [miller](https://www.trmn.sh/tools/miller.md): Command-line data processing tool for CSV, TSV, JSON, and JSON Lines with field-based operations (Go, 10.1k stars)
- [usql](https://www.trmn.sh/tools/usql.md): Universal command-line SQL client with PostgreSQL psql-inspired interface for multiple databases (Go, 10.2k stars)
- [lazysql](https://www.trmn.sh/tools/lazysql.md): Cross-platform TUI database management tool for MySQL, PostgreSQL, SQLite, and MSSQL with SQL editor and table operations. (Go, 4.4k stars)

---

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