Skip to content

Instantly share code, notes, and snippets.

@mys10gan
Created October 1, 2024 15:10
Show Gist options
  • Save mys10gan/db06f3171052df9685a5259ba327caed to your computer and use it in GitHub Desktop.
Save mys10gan/db06f3171052df9685a5259ba327caed to your computer and use it in GitHub Desktop.
Download any website and its assets
#!/bin/bash
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging function
log() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# Function to download website
download_website() {
if [ $# -eq 0 ]; then
log $RED "Error: No URL provided."
log $YELLOW "Usage: $0 <URL> [output_directory]"
exit 1
fi
url=$1
output_dir="${2:-website_download}"
log $BLUE "Starting download of $url"
log $YELLOW "Downloading to directory: $output_dir"
wget --recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains $(echo $url | awk -F[/:] '{print $4}') \
--no-parent \
-P "$output_dir" \
"$url"
if [ $? -eq 0 ]; then
log $GREEN "Download completed successfully."
log $YELLOW "Website files are in the '$output_dir' directory."
else
log $RED "An error occurred during the download."
fi
}
# Main execution
download_website "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment