- Notifications
You must be signed in to change notification settings - Fork8
orf/html-query
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
jq, but for HTML.Try it in your browser here
hq reads HTML and converts it into a JSON object based on a series of CSS selectors. The selectors are expressedin a similar way to JSON, but where the values are CSS selectors. For example:
{posts: .athing | [ {title: .titleline > a, url: .titleline > a | @(href)} ] }This will select all.athing elements, and it will create an array (| [{...}]) of objects for each element selected.Then for each element it will select the text of thetitleline > a element, and thehref attribute (| @(href)).
The end result is the following structure:
{"posts": [ {"title":"...","url":"..." } ]}brew install hq, orcargo install html-query
.foo | @text
This will select the text content from the first element matching.foo.
.foo | @(href)
This will select thehref attribute from the first element matching.foo.
.foo | @parent
This will return the parent element from the first element matching.foo.
.foo | @sibling(1)
This will return the sibling element from the first element matching.foo.
{posts: .athing | [{href: .titleline > a | @(href), title: .titleline > a, meta: @sibling(1) | {user: .hnuser, posted: .age | @(title) }}]}This selects each.athing element, extracts the URL from thehref attribute as well as the title. It then selectsthesibling.athing element, and extracts the user and post time from that:
{"posts": [ {"title":"...","url":"...","meta": {"posted":"...","user":"..." } } ]}About
jq, but for HTML
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
