As a developer, I recently faced a frustrating challenge: I needed to build a feature that analyzed Instagram Posts and Reels to extract engagement metrics, author details, and direct media URLs.
Initially, I tried writing a custom web scraper. However, I immediately hit a wall. Instagram's strict anti-bot systems kept blocking my requests, forcing me into an endless cycle of rotating proxies and struggling with complex User-Agent spoofing and parsing just to bypass login walls. Extracting clean user and engagement data from the minified DOM was a nightmare.
Just as I was about to give up on the feature, I discovered a sample source code repository on GitHub that completely solved my problem:
https://github.com/lunar-echo-5433/instagram-media-analyzer-api
Here is how this lightweight repository helped me bypass the User-Agent parsing headaches and streamline my entire workflow.
The Solution: A Lightweight Python Wrapper
The repository provides a lightweight Python wrapper and CLI utility designed to extract direct media download URLs, author profiles, and key engagement metrics from Instagram posts, Reels, and Carousels.
Instead of forcing you to manage User-Agents or parse complex HTML, it securely routes your requests through the Instagram Media Downloader & Scraper API on RapidAPI. By using the requests library and passing the x-rapidapi-key and x-rapidapi-host headers, the API handles all the heavy lifting behind the scenes.
Key Features That Saved My Project
The tool immediately gave me access to exactly what I needed without the scraping hassle:
Engagement Insights: I could easily retrieve total likes, video views, and comment counts.
Author Details: The tool extracts author handles (
username) and display names (full_name).Direct CDN URLs: It extracts high-resolution photo and HD video download links.
Carousel Extraction: It effortlessly parses multi-item carousel posts with item count metadata.
How Easy Was It to Implement?
The setup process was incredibly straightforward.
Prerequisites: I signed up for a RapidAPI account and subscribed to the API, which generously includes a free tier of up to 1,000 requests per month.
Installation: After cloning the repository, I simply set up a virtual environment and installed the required
requestsandpython-dotenvpackages.Configuration: The script uses
python-dotenvto securely load theRAPIDAPI_KEYfrom a.envfile, keeping credentials safe.
The Code in Action
The repository includes a brilliantly simple class called InstagramAnalyzer. It handles all the error checking (like 400 Bad Request or 403 Unauthorized errors) and returns a clean, structured JSON response.
Here is an example of how easily I was able to parse a target URL and pull the data in my own script:
from instagram_analyzer import InstagramAnalyzer
# Initialize with the RapidAPI key (can also rely on the .env file)
analyzer = InstagramAnalyzer(api_key="YOUR_RAPIDAPI_KEY")
# Parse the target Instagram URL
data = analyzer.parse_media("https://www.instagram.com/p/C_123456789/")
# Accessing the structured data is now trivial
print(data["author"]["username"])
print(data["metrics"]["like_count"])
for item in data["media"]:
print(item["download_url"])
(Code structure based on the repository's usage example)
The repository also includes a handy print_summary utility method that formats the output perfectly in the terminal, showing the Post ID, Caption, Metrics, and a complete Media Breakdown.
Conclusion
If you are a developer struggling with User-Agent blocking, rate limits, or DOM parsing while trying to analyze Instagram Reels and posts, I highly recommend checking out this GitHub repository. It turned a complex, blocked scraping task into a simple, reliable API call, saving me hours of development time.
Top comments (0)