Process HTML from jq - no dependency
<!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> |
|
# 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# 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)'Run non-regression tests with
./tests.shsee ./tests/ for list