Skip to content

Instantly share code, notes, and snippets.

@waynegraham
Created October 19, 2017 14:29
Show Gist options
  • Select an option

  • Save waynegraham/9a9e82bbcfe9a6ab737f0d6b39c24448 to your computer and use it in GitHub Desktop.

Select an option

Save waynegraham/9a9e82bbcfe9a6ab737f0d6b39c24448 to your computer and use it in GitHub Desktop.
#!/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