Skip to content

Instantly share code, notes, and snippets.

@knbknb
Last active July 21, 2022 21:12
Show Gist options
  • Save knbknb/31b20db2357b41622d692eeb17e8eaaf to your computer and use it in GitHub Desktop.
Save knbknb/31b20db2357b41622d692eeb17e8eaaf to your computer and use it in GitHub Desktop.
XPath: common queries with curl and xidel
# attribute values
curl -sL "${url}${urlparams}" \
| xidel -s -e "distinct-values(//node()[attribute::*])" \
| perl -ple 's/\s+$//' \
| cat -s -n | head -100
# attribute names
curl -sL "${url}${urlparams}" | xidel -s -e 'distinct-values(//@*)'
# element names in a document
curl -sL "${url}${urlparams}" | xidel -s -e "distinct-values(//*/name())" | xargs
# all Dublic-Core metadata from all *.svg documents in the current directory tree
grep -lR metadata * 2>/dev/null \
| xargs -i xidel -s -e '//metadata//dc:*/normalize-space()' {} \
| cat -s | more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment