Repository: mgdm/htmlq
Branch: master
Commit: 6e31bc814332
Files: 10
Total size: 27.2 KB
Directory structure:
gitextract_o4u0r91v/
├── .github/
│ └── workflows/
│ └── build.yml
├── .gitignore
├── Cargo.toml
├── LICENSE.md
├── README.md
├── flake.nix
├── src/
│ ├── link.rs
│ ├── main.rs
│ └── pretty_print.rs
└── tests/
└── cli.rs
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/workflows/build.yml
================================================
name: Build binaries
on:
release:
types: [published]
jobs:
release:
permissions:
contents: write
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
- name: Build release
run: cargo build --release
- name: Archive as .tar.gz (Linux)
if: matrix.os == 'ubuntu-latest'
run: tar cfz htmlq-x86_64-linux.tar.gz -C target/release htmlq
- name: Archive as .tar.gz (macOS)
if: matrix.os == 'macos-latest'
run: tar cfz htmlq-x86_64-darwin.tar.gz -C target/release htmlq
- name: Archive as .zip (Windows)
if: matrix.os == 'windows-latest'
shell: bash
run: 7z a -tzip -mm=Deflate htmlq-x86_64-windows.zip ./target/release/htmlq.exe
- name: Publish
uses: softprops/action-gh-release@v1
with:
files: |
htmlq*.tar.gz
htmlq*.zip
================================================
FILE: .gitignore
================================================
/target
**/*.rs.bk
================================================
FILE: Cargo.toml
================================================
[package]
name = "htmlq"
description = "Like jq, but for HTML."
categories = ["command-line-utilities"]
keywords = ["CSS", "HTML", "query"]
repository = "https://github.com/mgdm/htmlq"
documentation = "https://github.com/mgdm/htmlq/blob/master/README.md"
readme = "README.md"
license = "MIT"
license-file = "LICENSE.md"
version = "0.4.0"
authors = ["Michael Maclean "]
edition = "2021"
exclude = ["/.github"]
[dependencies]
kuchiki = "0.8.1"
html5ever = "0.25.1"
clap = "2.33.3"
lazy_static = "1.4.0"
url = "2.2.2"
[dev-dependencies]
assert_cmd = "2.0"
predicates = "2.1"
================================================
FILE: LICENSE.md
================================================
MIT License
Copyright (c) 2019 Michael Maclean
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# htmlq
Like [`jq`](https://stedolan.github.io/jq/), but for HTML. Uses [CSS selectors](https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Selectors) to extract bits of content from HTML files.
## Installation
### [Cargo](https://crates.io/crates/htmlq)
```sh
cargo install htmlq
```
### [FreeBSD pkg](https://www.freshports.org/textproc/htmlq)
```sh
pkg install htmlq
```
### [Homebrew](https://formulae.brew.sh/formula/htmlq)
```sh
brew install htmlq
```
### [Scoop](https://scoop.sh/)
```sh
scoop install htmlq
```
## Usage
```console
$ htmlq -h
htmlq 0.4.0
Michael Maclean
Runs CSS selectors on HTML
USAGE:
htmlq [FLAGS] [OPTIONS] [--] [selector]...
FLAGS:
-B, --detect-base Try to detect the base URL from the tag in the document. If not found, default to
the value of --base, if supplied
-h, --help Prints help information
-w, --ignore-whitespace When printing text nodes, ignore those that consist entirely of whitespace
-p, --pretty Pretty-print the serialised output
-t, --text Output only the contents of text nodes inside selected elements
-V, --version Prints version information
OPTIONS:
-a, --attribute Only return this attribute (if present) from selected elements
-b, --base Use this URL as the base for links
-f, --filename The input file. Defaults to stdin
-o, --output The output file. Defaults to stdout
-r, --remove-nodes ... Remove nodes matching this expression before output. May be specified multiple
times
ARGS:
... The CSS expression to select [default: html]
$
```
## Examples
### Using with cURL to find part of a page by ID
```console
$ curl --silent https://www.rust-lang.org/ | htmlq '#get-help'