Skip to content

Instantly share code, notes, and snippets.

@charmparticle
Created May 11, 2025 23:42
Show Gist options
  • Select an option

  • Save charmparticle/3253f75880d8daf546e5fb2dd4437213 to your computer and use it in GitHub Desktop.

Select an option

Save charmparticle/3253f75880d8daf546e5fb2dd4437213 to your computer and use it in GitHub Desktop.
xidel is faster than xpe, so I use this instead
#!/bin/bash
show_help(){
echo "invocation:
$0 <file> <xpath>
or
cat <file> | $0 <xpath>
examples:
cat file.html | $0 '//a/@href'
$0 '//a/@href' file.html
$0 file.html '//a/@href'
"
}
if [ -t 0 ]
then
#data is being supplied on the commandline, so parse a file
if [[ $# == 2 ]]
then
if [[ -e "$1" ]]
then
xidel -s --data "$1" --xpath "$2"
elif [[ -e "$2" ]]
then
xidel -s --data "$2" --xpath "$1"
else
show_help
fi
else
show_help
fi
else
if [[ $# == 1 ]]
then
xidel -s --data - --xpath "$1"
else
show_help
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment