Skip to content

Instantly share code, notes, and snippets.

@insanj
Last active May 15, 2020 20:41
Show Gist options
  • Save insanj/697dee28566ecc0ee5e459c6121a1577 to your computer and use it in GitHub Desktop.
Save insanj/697dee28566ecc0ee5e459c6121a1577 to your computer and use it in GitHub Desktop.
๐Ÿ“ธ Download All Photos From A User's Instagram Page

๐Ÿ“ธ Download All Photos From A User's Instagram Page

NOTE: This documentation/tool is for personal backup use ONLY. This is intentionally NOT built to be a "once and done" script to prevent abuse of the Instagram terms.

  1. Go to an Instagram user's page and grab all URLs using the Javascript console. Try the following command:
Array.prototype.slice.call(document.getElementsByTagName("img")).map(e => e.getAttribute("src")).join("\n")
  1. Copy and paste all the URLs you want to backup into a text file, such as files.txt. Make sure all URLs begin with the right base (in this case, instagram.com).
https://instagram.fphl2-4.fna.fbcdn.net/v/t51.2885-19/s320x320/89473677_2499649937031716_2450743282951520256_n.jpg?_nc_ht=instagram.fphl2-4.fna.fbcdn.net&_nc_ohc=Od441iwkPQoAX-hruDl&oh=261ba8060830f7c127644d234aa97c20&oe=5EE97402
https://instagram.fphl2-3.fna.fbcdn.net/v/t51.2885-15/sh0.08/e35/c0.180.1440.1440a/s640x640/96860792_523158148562685_7608590519194590096_n.jpg?_nc_ht=instagram.fphl2-3.fna.fbcdn.net&_nc_cat=109&_nc_ohc=hLMeMxJDnf8AX8bzBJa&oh=68b0cd7418d27eba9813928c5502fc7e&oe=5EE96C09
...
  1. Run the following batch curl command from the location where you saved file.txt using Terminal/iTerm:
xargs -n 1 curl -O < files.txt
  1. You may notice that the downloaded files do not have a valid file extension due to the long URL queries at the end. You can use the homebrew tool rename (install with brew install rename) to fix this pretty easily:
rename --append .jpg *
  1. ๐ŸŽ‰ Done! Enjoy your folder of photos. To ensure as many high quality photos are saved as possible, browse the user's page for a while before running the command.

Looking for BETTER quality photos, but ONE a time?

Use the following script that tries to pull the image from an open dialog using a silly little padding-bottom check. It should open the image in a new window:

for (const i of Array.prototype.slice.call(document.getElementsByTagName("img")).filter(e => e.parentNode.style.paddingBottom === "125%").map(e => e.getAttribute("src"))) {
	const f = document.createElement('a');
	f.href = i;
	f.download = i;
	document.body.appendChild(f);
	f.click();
	document.body.removeChild(f);
}

As a bookmarklet:

javascript:(function(){for(const e of Array.prototype.slice.call(document.getElementsByTagName("img")).filter(e=>e.parentNode.style.paddingBottom).map(e=>e.getAttribute("src"))){const t=document.createElement("a");t.href=e,t.download=e,document.body.appendChild(t),t.click(),document.body.removeChild(t)}})();```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment