https://github.com/khanhas/hq
hq is like jq for HTML
https://github.com/khanhas/hq
Last synced: 24 days ago
JSON representation
hq is like jq for HTML
- Host: GitHub
- URL: https://github.com/khanhas/hq
- Owner: khanhas
- License: mit
- Created: 2019-06-24T15:16:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-06-26T10:00:22.000Z (almost 6 years ago)
- Last Synced: 2025-05-01T00:04:07.289Z (about 1 month ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hq
hq is like [jq](https://stedolan.github.io/jq/) for HTML## Install
```
npm i hqcl
```## Usage
```
hq " | ..." []
```
- `query` to get elements.
- Syntax is the same as syntax you use in `document.querySelectorAll` or `jquery`: `#elementId .elementClassName elemen-tag`.
- Returns list of matched elements.
- Examples: `div.title`, `#footer .link`, `.result.active`
- `slice`: Get portion of results.
- Syntax: `.[:]`
- Returs sliced list of results
- Examples: `.[:6]`, `.[2:10]`, `.[5:]`
- `member`: Get a member of results
- Syntax: `.`
- Examples: `.textContent`, `.length`
- `method`: Invoke a method of results
- Syntax: ``, ``
- Examples: `getAttribute(href)`, `toUpperCase`Keep "piping" in `hq` argument until you get the final result you want or use other unix's string processing utilites.
### Feed HTML
#### From `stdin`:
```bash
html=$(curl https://duckduckgo.com/html?q=feet)
echo $html | hq ".result__a | .textContent"
```#### From file/url:
```bash
hq ".result__a | .textContent" ~/toes.html
```
```bash
hq ".result__a | .textContent" "https://duckduckgo.com/html?q=ankle"
```