Created
October 19, 2017 14:29
-
-
Save waynegraham/9a9e82bbcfe9a6ab737f0d6b39c24448 to your computer and use it in GitHub Desktop.
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 | |
| #Description: Images downloader | |
| #Filename: img_downloader.sh | |
| if [ $# -ne 3 ]; | |
| then | |
| echo "Usage: $0 URL -d DIRECTORY" | |
| exit -1 | |
| fi | |
| for i in {1..4} | |
| do | |
| case $1 in | |
| -d) shift; directory=$1; shift ;; | |
| *) url=${url:-$1}; shift;; | |
| esac | |
| done | |
| mkdir -p $directory; | |
| baseurl=$(echo $url | egrep -o "https?://[a-z.]+") | |
| curl –s $url | egrep -o "<img src=[^>]*>" | sed 's/<img src=\"\([^"]*\).*/\1/g' > /tmp/$$.list | |
| sed -i "s|^/|$baseurl/|" /tmp/$$.list | |
| cd $directory; | |
| while read filename; | |
| do | |
| curl –s -O "$filename" --silent | |
| done < /tmp/$$.list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment