Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nick-f/31c10ec1b722806dbc54ef24a170f9f0 to your computer and use it in GitHub Desktop.
Save nick-f/31c10ec1b722806dbc54ef24a170f9f0 to your computer and use it in GitHub Desktop.
Download images from my Instagram profile easily
var images = document.querySelectorAll('._jjzlb > img'); images;

Hi future me,

Here's how I past me downloaded all of my Instagram photos easily. Remember, it doesn't download likes, comment, or any other information apart from the photos themselves.

For whatever reason Photoshop doesn't want to open the images but Preview works fine. It's the same when I manually downloaded the photos from the Instagram website. (Sabotage?)

And of course everyone else who isn't you will stop reading at this point and not use the instructions, right? Good. Now that it's just us...

Requirements

  • wget

Instructions

  1. In your browser, go to your profile.
  2. Click "Load More" and scroll down to load all of the images that you want to save from your profile.
  3. Open the Developer console in your browser.
  4. Paste the command from browser_command.js. This looks at the Instagram page source for all items that have a class of jjzlb and gets the img elements in them. (If Instagram changes that class name in the future then you'll need to update this).
  5. Copy the resulting array into a file on your computer.
  6. Set permissions for the .sh script. e.g. chmod u+x downloader.sh
  7. Run it. ./downloader.sh images.txt

The images in the file will be saved with the description as the filename and a number at the start of each filename to keep them in order. If you've used this before and are wanting to keep the number of your photos going, change line 9 in downloader.sh to be whatever number you want it to start at next.

#!/bin/bash
if [[ -z $1 ]]; then
echo "Error: Run the script with the filename as an argument."
echo "Example: $0 images.txt"
else
tail -r $1 > reversed
i=1
while read p; do
imgtag=`echo $p | cut -d'"' -f 1`
if [[ $imgtag == "<img alt=" ]]; then
description=`echo -n $p | cut -d'"' -f 2`
image=`echo -n $p | cut -d'"' -f 8`
echo "Downloading $description"
wget -q $image -O "$i - $description.jpg"
((i++))
fi
done<reversed
rm reversed
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment