1.2.0 • Published 6 years ago
hqcl v1.2.0
hq
hq is like jq for HTML
Install
npm i hqclUsage
hq "<query> | <slice or member or method>..." [<url or file>]queryto get elements.- Syntax is the same as syntax you use in
document.querySelectorAllorjquery:#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
From stdin:
html=$(curl https://duckduckgo.com/html?q=feet)
echo $html | hq ".result__a | .textContent"From file/url:
hq ".result__a | .textContent" ~/toes.htmlhq ".result__a | .textContent" "https://duckduckgo.com/html?q=ankle"