Skip to content
ynePublic

About

jq HTML/XML parser to JSONML

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

html.jq

Process HTML from jq - no dependency

PREVIEW

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Basic Example</title>
    <link rel="stylesheet" />
  </head>
  <body id="home">
    <input type="text"/>
    <p>content</p>
  </body>
</html>
// doctype is ommited
["html",{"lang":"en"},[
    ["head", {}, [
        ["meta", {"charset": "utf-8"} ],
        ["title", {}, ["Basic Example"] ],
        ["link", {"rel": "stylesheet"} ]
    ]],
    ["body", {"id": "home"}, [
        ["input", {"type": "text"}],
        ["p", {}, ["content"]]
    ]]
]]

USAGE

# basic example
jq -sRf ./html.jq < tests/base.html
# possible direct call
        ./html.jq < tests/base.html
# piping from curl
curl example.com | ./html.jq

EXAMPLES

# select all "a" element's .href, i.e. $$("a").map(a=>a.href)
cat my.html | jq -sRf html.jq | jq '..|arrays|select(.[0]=="a")[1].href'
# select element by .id attribute, i.e. $$("[id=footer]")
cat my.html | jq -sRf html.jq | jq '..|arrays|select(try(.[1].id == "footer") catch false)'

TESTS

Run non-regression tests with

./tests.sh

see ./tests/ for list

About

jq HTML/XML parser to JSONML

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages