Skip to content

Instantly share code, notes, and snippets.

@pwnwriter
Created March 20, 2023 05:40
Show Gist options
  • Save pwnwriter/98336ae2a629997944447a4de92034fc to your computer and use it in GitHub Desktop.
Save pwnwriter/98336ae2a629997944447a4de92034fc to your computer and use it in GitHub Desktop.
A pure bash script to take screenshots of url/webpages from </> .
#!/usr/bin/env bash
# Change this to the dimensions you want the screenshots to be in
width="1366"
height="768"
# Check if the directory and URLs are provided as arguments
if [ $# -lt 2 ]; then
echo "Usage: $0 <directory> <url1|urls_file>"
exit 1
fi
# Set the directory and URL(s)
directory=$1
urls=$2
# Create the directory if it doesn't exist
if [ ! -d "$directory" ]; then
mkdir -p "$directory"
fi
# Define a function to take a screenshot of a URL
take_screenshot() {
local url=$1
local filename=${url//[^a-zA-Z0-9]/-}
google-chrome-stable \
--headless \
--disable-gpu \
--screenshot="$directory/$filename.png" \
--window-size="$width,$height" \
"$url" \
2>/dev/null
echo " Took screenshot of $url and saved to $directory directory"
}
# Check if the URLs is a file or a single URL
if [ -f "$urls" ]; then
# Loop through the URLs in the file and take screenshots
while read -r url; do
take_screenshot "$url"
done < "$urls"
else
# Take a screenshot of the single URL
take_screenshot "$urls"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment