<commit_before># hq
**Powerful HTML slicing and dicing at the command line.**

[![Build Status](https://travis-ci.org/rbwinslow/hq.svg?branch=master)](https://travis-ci.org/rbwinslow/hq) [![Coverage Status](https://coveralls.io/repos/github/rbwinslow/hq/badge.svg?branch=master)](https://coveralls.io/github/rbwinslow/hq?branch=master)

`hq` is a Python-based command-line tool for querying HTML, manipulating data and producing results as HTML, JSON or any other format. It's based on a compact, flexible expression language that started out as an XPath implementation but ended up going a few different places, so I'm going ahead and calling it HQuery.

HQuery is 99% compliant with the [XPath 1.0](https://www.w3.org/TR/xpath/) standard, minus some features not applicable to HTML. That's nice for querying, but you need more power to take control of the shape and format of the data you produce. To that end, HQuery also includes...

* **Nuggets of XQuery** &mdash; only a few of the good parts! Just enough for iteration, branching and the like.
* **XPath expansions for HTML** &mdash; including a `class::` axis and `class()` function, plus abbreviated axes to keep things terse.
* **Super-charged string interpolation** &mdash; with powerful filters that you can chain together to transform data as you produce it.
* **Computed constructors for HTML and JSON** &mdash; so you can programmatically assemble and output new HTML or JSON objects and arrays.

## Installing `hq`

    pip install hq

## Running `hq`

    cat /path/to/file.html | hq '`Hello, ${/html/head/title}`!'

...or...

    hq -f /path/to/file.html '`Hello, ${/html/head/title}`!'
    
To print usage information:

    hq --help
<commit_msg>Fixed code sample typos in README.<commit_after># hq
**Powerful HTML slicing and dicing at the command line.**

[![Build Status](https://travis-ci.org/rbwinslow/hq.svg?branch=master)](https://travis-ci.org/rbwinslow/hq) [![Coverage Status](https://coveralls.io/repos/github/rbwinslow/hq/badge.svg?branch=master)](https://coveralls.io/github/rbwinslow/hq?branch=master)

`hq` is a Python-based command-line tool for querying HTML, manipulating data and producing results as HTML, JSON or any other format. It's based on a compact, flexible expression language that started out as an XPath implementation but ended up going a few different places, so I'm going ahead and calling it HQuery.

HQuery is 99% compliant with the [XPath 1.0](https://www.w3.org/TR/xpath/) standard, minus some features not applicable to HTML. That's nice for querying, but you need more power to take control of the shape and format of the data you produce. To that end, HQuery also includes...

* **Nuggets of XQuery** &mdash; only a few of the good parts! Just enough for iteration, branching and the like.
* **XPath expansions for HTML** &mdash; including a `class::` axis and `class()` function, plus abbreviated axes to keep things terse.
* **Super-charged string interpolation** &mdash; with powerful filters that you can chain together to transform data as you produce it.
* **Computed constructors for HTML and JSON** &mdash; so you can programmatically assemble and output new HTML or JSON objects and arrays.

## Installing `hq`

    pip install hq

## Running `hq`

    cat /path/to/file.html | hq '`Hello, ${/html/head/title}!`'

...or...

    hq -f /path/to/file.html '`Hello, ${/html/head/title}!`'
    
To print usage information:

    hq --help

{'fraction_non_alphanumeric': 0.11330049261083744, 'fraction_numerical': 0.0028977108084613156, 'mean_word_length': 4.238239757207891, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4275340', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1021, 'n_words': 431}