Created
October 1, 2024 15:10
-
-
Save mys10gan/db06f3171052df9685a5259ba327caed to your computer and use it in GitHub Desktop.
Download any website and its assets
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 | |
# 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