Skip to content

Instantly share code, notes, and snippets.

@jamescherti
Last active December 25, 2022 22:05
Show Gist options
  • Save jamescherti/8ee95c52d283671ab314afb09feab9dc to your computer and use it in GitHub Desktop.
Save jamescherti/8ee95c52d283671ab314afb09feab9dc to your computer and use it in GitHub Desktop.
Shell: extract all download links from a URL.
#!/usr/bin/env sh
# Description: extract all download links from a URL.
# Usage: get_urls "https://domain.com/page"
# Requirements: lynx, sed, grep, and bash.
# Author: James Cherti
# URL: https://gist.github.com/jamescherti/8ee95c52d283671ab314afb09feab9dc
# License: MIT
get_urls() {
if [ $# -lt 1 ]; then
echo "Usage: geturls <url>" >&2
return 1
fi
local urls="$1"
LC_ALL=C lynx -dump -listonly "$urls" | sed -e 's/^\([0-9\s. ]\+\)//g' | grep -v '^$' | grep -vi '^references$' | grep -v '/$'
return "$?"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment