Created
May 11, 2025 23:42
-
-
Save charmparticle/3253f75880d8daf546e5fb2dd4437213 to your computer and use it in GitHub Desktop.
xidel is faster than xpe, so I use this instead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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