Skip to content

htmlq

Парсер html (аналогичный jq)
Репо: https://github.com/mgdm/htmlq

Install

Bash
pipx install htmlq

Usage

Получить все теги a:

Bash
curl -s https://www.rust-lang.org/ | htmlq 'a'

Получить содержимое тегов div
Bash
curl -s https://www.rust-lang.org/ | htmlq -t 'div'

Получить атрибут тегов div (in this case, класс):
Bash
curl -s https://www.rust-lang.org/ | htmlq -a 'class' 'div'

Поиск по классам, ID и их комбинации:
Bash
curl -s https://www.rust-lang.org/ | htmlq -t 'div.attribution'
curl -s https://www.rust-lang.org/ | htmlq -t '.attribution'
curl -s https://www.rust-lang.org/ | htmlq -t 'div#some_id'
curl -s https://www.rust-lang.org/ | htmlq -t '#some_id'
curl -s https://www.rust-lang.org/ | htmlq -t 'div.attribution#some_id'

Syntax highlighting w/ bat:
Bash
curl -s https://www.rust-lang.org/ | htmlq 'body' | bat --language html


htmlq #tool #html #scraping