close
The Wayback Machine - https://web.archive.org/web/20201107092850/https://github.com/khanhas/hq
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Jun 24, 2019
Jun 24, 2019
Jun 24, 2019

README.md

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 or jquery: #elementId .elementClassName elemen-tag.
    • Returns list of matched elements.
    • Examples: div.title, #footer .link, .result.active
  • slice: Get portion of results.
    • Syntax: .[<start>:<end>]
    • Returs sliced list of results
    • Examples: .[:6], .[2:10], .[5:]
  • member: Get a member of results
    • Syntax: .<member name>
    • Examples: .textContent, .length
  • method: Invoke a method of results
    • Syntax: <method name>, <method name(...args[])>
    • 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:

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"

About

hq is like jq for HTML

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.