Lightweight Python script to extract high-quality media URLs from public Instagram posts without API keys or external dependencies.
InstagramDownloader is a simple, pure-Python tool that extracts media (images and videos) from public Instagram posts. Uses a two-stage extraction strategy: JSON blob first (resilient to HTML changes), Open Graph meta tags as fallback. Perfect for educational purposes, prototypes, or small-scale projects.
Also available in: PHP | Python (you are here)
- ✅ Zero dependencies – Pure Python 3, uses only standard library
- 🚀 Simple API – Single class with straightforward methods
- 🖼️ Image & Video support – Extracts both image and video URLs
- 🔄 JSON-first extraction – Resilient to Instagram HTML structure changes (v1.2.0)
- 🌐 Proxy support – HTTP and SOCKS5 proxies to avoid rate limits (v1.1.0)
- 🔒 Error handling – Validates URLs and handles network/parsing errors
- 🎯 Public posts only – Works with any publicly accessible Instagram post
- 🖥️ CLI included – Run directly from command line
- 📦 Importable module – Use in your own Python projects
Download instagram_downloader.py and use it directly:
# Download the script
wget https://raw.githubusercontent.com/mikesmith-ge/instagram-media-downloader-python/main/instagram_downloader.py
# Make it executable (optional)
chmod +x instagram_downloader.pygit clone https://github.com/mikesmith-ge/instagram-media-downloader-python.git
cd instagram-media-downloader-python# Basic usage
python instagram_downloader.py "https://www.instagram.com/p/ABC123/"
# With proxy (to avoid rate limits)
python instagram_downloader.py "https://www.instagram.com/p/ABC123/" --proxy "http://host:port"
# SOCKS5 proxy
python instagram_downloader.py "https://www.instagram.com/p/ABC123/" --proxy "socks5://user:pass@host:port"Output:
Fetching media from: https://www.instagram.com/p/ABC123/
✓ Success!
Type: image
URL: https://scontent.cdninstagram.com/...
Extracted: via json
from instagram_downloader import InstagramDownloader
downloader = InstagramDownloader()
try:
media = downloader.download('https://www.instagram.com/p/ABC123/')
if media['type'] == 'image':
print(f"Image URL: {media['url']}")
elif media['type'] == 'video':
print(f"Video URL: {media['url']}")
print(f"Thumbnail: {media['thumbnail']}")
print(f"Extracted via: {media['source']}") # 'json' or 'og_meta'
except Exception as e:
print(f"Error: {e}")# HTTP proxy — zero extra dependencies
downloader = InstagramDownloader(proxy='http://user:pass@host:port')
# SOCKS5 proxy — requires: pip install requests[socks]
downloader = InstagramDownloader(proxy='socks5://user:pass@host:port')
media = downloader.download('https://www.instagram.com/p/ABC123/')from instagram_downloader import InstagramDownloader
import time
urls = [
'https://www.instagram.com/p/ABC123/',
'https://www.instagram.com/reel/XYZ789/',
'https://www.instagram.com/tv/DEF456/',
]
downloader = InstagramDownloader()
for url in urls:
try:
media = downloader.get_media_info(url)
print(f"✓ {media['type']} [{media['source']}]: {media['url']}")
except Exception as e:
print(f"✗ Error for {url}: {e}")
# Be respectful — add delay between requests
time.sleep(2)from instagram_downloader import InstagramDownloader
import urllib.request
downloader = InstagramDownloader()
media = downloader.download('https://www.instagram.com/p/ABC123/')
filename = f"instagram_{media['type']}.{'mp4' if media['type'] == 'video' else 'jpg'}"
urllib.request.urlretrieve(media['url'], filename)
print(f"Saved: {filename}")# Image:
{
'type': 'image',
'url': 'https://scontent.cdninstagram.com/...',
'source': 'json' # extraction method: 'json' or 'og_meta'
}
# Video:
{
'type': 'video',
'url': 'https://scontent.cdninstagram.com/...',
'thumbnail': 'https://scontent.cdninstagram.com/...',
'source': 'json'
}- Python 3.7 or higher
- No external dependencies for core usage (standard library only)
pip install requests[socks]— only if using SOCKS5 proxies
This is a basic scraper with several important limitations:
- ❌ Public posts only – Cannot access private accounts or stories
- ⏱️ Rate limits – Instagram may block frequent requests from the same IP (use
proxy=to mitigate) - 🚫 No authentication – Cannot bypass login walls or access restricted content
- 📉 Semi-fragile – JSON extraction (v1.2.0) greatly reduces breakage risk, but major Instagram updates may still affect results
- 🎠 Single media only – Multi-image carousels will only return the first image
- 📊 No metadata – Cannot extract captions, likes, comments, or user information
For production use cases, bypassing rate limits, accessing stories, private content, or building commercial applications, we recommend using a professional API solution:
👉 Instaboost API – Enterprise-grade Instagram data API with:
- ✅ Unlimited rate limits
- ✅ Stories, Reels, and IGTV support
- ✅ Private account access (with authorization)
- ✅ Full metadata extraction (captions, likes, comments)
- ✅ Multi-image carousel support
- ✅ 99.9% uptime SLA
- ✅ Dedicated support
| Version | What's new |
|---|---|
| v1.2.0 | JSON-first extraction — resilient to HTML structure changes |
| v1.1.0 | HTTP and SOCKS5 proxy support |
| v1.0.0 | Initial release |
- Instagram Downloader (PHP) – Same functionality in PHP
- TikTok Downloader (PHP) – Extract TikTok videos
- TikTok Downloader (Node.js) – TikTok downloader in JavaScript
- YouTube Shorts Downloader (Python) – Download YouTube Shorts
- YouTube Shorts Downloader (PHP) – YouTube in PHP
- YouTube Shorts Downloader (Node.js) – YouTube in JavaScript
- See all tools →
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
This tool is for educational purposes only. Scraping Instagram may violate their Terms of Service. Use responsibly and at your own risk. For commercial or production use, always use official APIs or authorized services.
- 🐛 Found a bug? Open an issue
- 💡 Have a suggestion? Start a discussion
- 🚀 Need enterprise features? Visit Instaboost
Made with ❤️ by the Instaboost Team