hq
hq is like jq for HTML
Install
npm i hqcl
Usage
hq "<query> | <slice or member or method>..." [<url or file>]
query
to get elements.- Syntax is the same as syntax you use in
document.querySelectorAll
orjquery
:#elementId .elementClassName elemen-tag
. - Returns list of matched elements.
- Examples:
div.title
,#footer .link
,.result.active
- Syntax is the same as syntax you use in
slice
: Get portion of results.- Syntax:
.[<start>:<end>]
- Returs sliced list of results
- Examples:
.[:6]
,.[2:10]
,.[5:]
- Syntax:
member
: Get a member of results- Syntax:
.<member name>
- Examples:
.textContent
,.length
- Syntax:
method
: Invoke a method of results- Syntax:
<method name>
,<method name(...args[])>
- Examples:
getAttribute(href)
,toUpperCase
- Syntax:
Keep "piping" in hq
argument until you get the final result you want or use other unix's string processing utilites.
Feed HTML
stdin
:
From html=$(curl https://duckduckgo.com/html?q=feet)echo $html | hq ".result__a | .textContent"
From file/url:
hq ".result__a | .textContent" ~/toes.html
hq ".result__a | .textContent" "https://duckduckgo.com/html?q=ankle"