├── cookies.txt ├── requirements.txt ├── vercel.json ├── LICENSE ├── app.py ├── README.md └── status.html /cookies.txt: -------------------------------------------------------------------------------- 1 | Your NetScape Format Cookies Here 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | instaloader 3 | requests 4 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "builds": [ 4 | { 5 | "src": "app.py", 6 | "use": "@vercel/python" 7 | } 8 | ], 9 | "routes": [ 10 | { 11 | "src": "/(.*)", 12 | "dest": "app.py" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 TheSmartDevs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, jsonify, send_file # Added send_file import 2 | import instaloader 3 | import os 4 | import re 5 | import http.cookiejar 6 | 7 | app = Flask(__name__) 8 | 9 | def validate_url(url): 10 | pattern = r'instagram\.com/(p|reel|tv)/([A-Za-z0-9-_]+)' 11 | match = re.search(pattern, url) 12 | if match: 13 | return match.group(2) 14 | return None 15 | 16 | def load_cookies_from_file(cookies_path): 17 | cookies = {} 18 | try: 19 | cookie_jar = http.cookiejar.MozillaCookieJar() 20 | cookie_jar.load(cookies_path, ignore_discard=True, ignore_expires=True) 21 | for cookie in cookie_jar: 22 | if cookie.name in ["sessionid", "csrftoken"] and cookie.domain == ".instagram.com": 23 | cookies[cookie.name] = cookie.value 24 | if "sessionid" in cookies and "csrftoken" in cookies: 25 | return cookies 26 | else: 27 | return None 28 | except Exception: 29 | return None 30 | 31 | def get_instagram_post_urls(url, cookies_file="cookies.txt"): 32 | result = { 33 | "status": "error", 34 | "message": "", 35 | "media_urls": [], 36 | "title": None, 37 | "author": None, 38 | "developer": "API Developer : @ISmartDevs", 39 | "channel": "Updates Channel : @TheSmartDev" 40 | } 41 | 42 | shortcode = validate_url(url) 43 | if not shortcode: 44 | result["message"] = "Please Provide Valid URL" 45 | return result 46 | 47 | try: 48 | loader = instaloader.Instaloader( 49 | user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36" 50 | ) 51 | 52 | script_dir = os.path.dirname(os.path.abspath(__file__)) 53 | cookies_path = os.path.join(script_dir, cookies_file) 54 | 55 | if not os.path.isfile(cookies_path): 56 | result["message"] = f"Cookies Missing Bro Add Cookies" 57 | return result 58 | 59 | cookies = load_cookies_from_file(cookies_path) 60 | if not cookies: 61 | result["message"] = "Invalid Cookies Provided Update Cookies" 62 | return result 63 | 64 | loader.context._session.cookies.set("sessionid", cookies["sessionid"], domain=".instagram.com") 65 | loader.context._session.cookies.set("csrftoken", cookies["csrftoken"], domain=".instagram.com") 66 | 67 | post = instaloader.Post.from_shortcode(loader.context, shortcode) 68 | 69 | media_urls = [] 70 | # For videos or images 71 | if post.is_video: 72 | media_urls.append(post.video_url) 73 | else: 74 | media_urls.append(post.url) 75 | 76 | # If sidecar (multiple media) 77 | if post.typename == "GraphSidecar": 78 | for node in post.get_sidecar_nodes(): 79 | media_urls.append(node.video_url if node.is_video else node.display_url) 80 | 81 | result["status"] = "success" 82 | result["message"] = "Media URLs extracted successfully." 83 | result["media_urls"] = media_urls 84 | result["title"] = post.caption if post.caption else "No caption" 85 | result["author"] = post.owner_username 86 | 87 | return result 88 | 89 | except instaloader.exceptions.LoginRequiredException: 90 | result["message"] = "Sorry Bro Private Post Need Proper Cookies" 91 | return result 92 | except instaloader.exceptions.BadResponseException as bre: 93 | result["message"] = f"Instagram Meta API Dead" 94 | return result 95 | except Exception as e: 96 | result["message"] = f"Error: {str(e)}" 97 | return result 98 | 99 | @app.route('/', methods=['GET']) 100 | def api_status(): 101 | """ 102 | Flask endpoint for API status page (GET request). 103 | Serves the status.html file. 104 | """ 105 | return send_file('status.html'), 200 106 | 107 | @app.route('/download', methods=['GET']) 108 | def download(): 109 | url = request.args.get("url") 110 | if not url: 111 | return jsonify({"status": "error", "message": "URL Required To Download Your Desired Media!"}), 400 112 | 113 | result = get_instagram_post_urls(url) 114 | status_code = 200 if result["status"] == "success" else 400 115 | return jsonify(result), status_code 116 | 117 | if __name__ == "__main__": 118 | app.run(host="0.0.0.0", port=5000, debug=True) 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## SmartDev's Instagram Scraper API 🌟 2 | 3 | ![GitHub stars](https://img.shields.io/github/stars/TheSmartDevs/Insta-Scrapper-API?style=social) 4 | ![GitHub forks](https://img.shields.io/github/forks/TheSmartDevs/Insta-Scrapper-API?style=social) 5 | ![GitHub issues](https://img.shields.io/github/issues/TheSmartDevs/Insta-Scrapper-API) 6 | ![License](https://img.shields.io/github/license/TheSmartDevs/Insta-Scrapper-API) 7 | 8 | Welcome to **SmartDev's Instagram Scraper API**! 🚀 This API allows developers to extract direct media URLs (images and videos) from Instagram posts and reels using a simple and reliable endpoint. Designed for developers and data enthusiasts, this open-source project provides clear documentation to integrate Instagram media scraping into your applications. 9 | 10 | --- 11 | 12 | ## 🌟 Features 13 | 14 | - **Fast & Reliable**: Extract media URLs from Instagram posts and reels quickly. 15 | - **Simple Endpoint**: Use a single GET request with a URL query parameter. 16 | - **Open Source**: Fully open-source and community-driven. 17 | - **Comprehensive Documentation**: Clear examples and notes for easy integration. 18 | 19 | --- 20 | 21 | ## 🚀 Getting Started 22 | 23 | ### Prerequisites 24 | - A valid Instagram account with session cookies (`sessionid` and `csrftoken`). 25 | - Basic knowledge of HTTP requests and JSON. 26 | - Node.js or any HTTP client for testing (e.g., Postman, cURL). 27 | 28 | ### Installation 29 | 1. **Clone the Repository**: 30 | ```bash 31 | git clone https://github.com/TheSmartDevs/Insta-Scrapper-API.git 32 | cd Insta-Scrapper-API 33 | ``` 34 | 35 | 2. **Install Dependencies**: 36 | ```bash 37 | npm install 38 | ``` 39 | 40 | 3. **Configure Cookies**: 41 | - Add your Instagram session cookies in `cookies/cookies.txt` in Netscape format. 42 | - Example: 43 | ``` 44 | # Netscape HTTP Cookie File 45 | .instagram.com TRUE / FALSE 0 sessionid your_session_id 46 | .instagram.com TRUE / FALSE 0 csrftoken your_csrf_token 47 | ``` 48 | 49 | 4. **Run the API**: 50 | ```bash 51 | npm start 52 | ``` 53 | 54 | 5. **Access the API**: 55 | - The API will be available at `http://localhost:3000` (or your deployed URL, e.g., `https://its-smart-dev.vercel.app`). 56 | 57 | --- 58 | 59 | ## 📚 API Documentation 60 | 61 | ### Endpoint: `GET /download` 62 | 63 | Extract media URLs from an Instagram post or reel. 64 | 65 | #### Request 66 | ```bash 67 | curl -X GET "https://your-api-url/download?url=https://www.instagram.com/p/XXXXX/" 68 | curl -X GET "https://your-api-url/download?url=https://www.instagram.com/reel/XXXXX/" 69 | ``` 70 | 71 | #### Response (Success) 72 | ```json 73 | { 74 | "status": "success", 75 | "message": "Media URLs extracted successfully.", 76 | "media_urls": [ 77 | "https://instagram.com/.../media1.jpg", 78 | "https://instagram.com/.../media2.mp4" 79 | ], 80 | "title": "Post caption", 81 | "author": "username", 82 | "developer": "API Developer : @ISmartDevs", 83 | "channel": "Updates Channel : @TheSmartDev" 84 | } 85 | ``` 86 | 87 | #### Response (Error) 88 | ```json 89 | { 90 | "status": "error", 91 | "message": "URL Required To Download Your Desired Media!", 92 | "media_urls": [], 93 | "title": null, 94 | "author": null, 95 | "developer": "API Developer : @ISmartDevs", 96 | "channel": "Updates Channel : @TheSmartDev" 97 | } 98 | ``` 99 | 100 | #### Notes 101 | - Requires valid Instagram session cookies in `cookies/cookies.txt` with `sessionid` and `csrftoken`. 102 | - The URL must be in the format `https://www.instagram.com/p/XXXXX/` for posts or `https://www.instagram.com/reel/XXXXX/` for reels. 103 | - Query parameters (e.g., `?igsh=...`) are ignored by the API. 104 | 105 | --- 106 | 107 | ## 🛠️ Usage Example 108 | 109 | ### Using JavaScript (Fetch) 110 | ```javascript 111 | const url = "https://www.instagram.com/p/XXXXX/"; 112 | fetch(`https://your-api-url/download?url=${encodeURIComponent(url)}`) 113 | .then(response => response.json()) 114 | .then(data => console.log(data)) 115 | .catch(error => console.error("Error:", error)); 116 | ``` 117 | 118 | ### Using Python (Requests) 119 | ```python 120 | import requests 121 | 122 | url = "https://www.instagram.com/reel/XXXXX/" 123 | response = requests.get(f"https://your-api-url/download?url={url}") 124 | print(response.json()) 125 | ``` 126 | 127 | --- 128 | 129 | ## 🌍 Contributing 130 | 131 | We love contributions! 💖 Follow these steps to contribute: 132 | 133 | 1. **Fork the Repository** 🍴 134 | 2. **Create a Branch**: 135 | ```bash 136 | git checkout -b feature-branch 137 | ``` 138 | 3. **Commit Changes**: 139 | ```bash 140 | git commit -m "Add new feature" 141 | ``` 142 | 4. **Push to Branch**: 143 | ```bash 144 | git push origin feature-branch 145 | ``` 146 | 5. **Open a Pull Request** 📬 147 | 148 | Check out the repository on [GitHub](https://github.com/TheSmartDevs/Insta-Scrapper-API). 149 | 150 | --- 151 | 152 | ## 📬 Contact Us 153 | 154 | Join our community and stay updated: 155 | 156 | - **Instagram**: [@ISmartDevs](https://x.com/abirxdhackz) 157 | - **Telegram**: [TheSmartDev](https://t.me/TheSmartDev) 158 | - **GitHub**: [@TheSmartDevs](https://github.com/TheSmartDevs/Insta-Scrapper-API) 159 | 160 | --- 161 | 162 | ## 🏆 Acknowledgments 163 | 164 | - Built with ❤️ by [TheSmartDevs](https://t.me/TheSmartDev). 165 | - Powered by [Bootstrap](https://getbootstrap.com), [Font Awesome](https://fontawesome.com), and [GSAP](https://greensock.com/gsap/) for the documentation site. 166 | - Special thanks to our contributors! 🌟 167 | 168 | --- 169 | 170 | ## 📝 License 171 | 172 | This project is licensed under the [MIT License](LICENSE). 173 | 174 | --- 175 | 176 | © 2025 SmartDev's Instagram Scraper API | Powered by [TheSmartDev](https://t.me/TheSmartDev) 177 | -------------------------------------------------------------------------------- /status.html: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | SmartDev's Insta Scraper API Documentation 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 316 | 317 | 318 | 319 |
320 | 321 | 322 |
323 |
324 |

SmartDev's Insta Scraper API

325 |

API documentation for extracting media URLs from Instagram posts and reels! ✨

326 | View Documentation 327 |
328 |
329 | 330 | 331 | 352 | 353 | 354 |
355 |

API Documentation 📚

356 |

API Status: Live ⚡️

357 |
358 |
359 |

360 | 363 |

364 |
365 |
366 |

Send a GET request to /download with an Instagram post or reel URL as a query parameter.

367 |
368 | Request Example:
369 | curl -X GET "https://its-smart-dev.vercel.app/download?url=https://www.instagram.com/p/XXXXX/"
370 | curl -X GET "https://its-smart-dev.vercel.app/download?url=https://www.instagram.com/reel/XXXXX/"
371 | 
372 | Response Example (Success):
373 | {
374 |   "status": "success",
375 |   "message": "Media URLs extracted successfully.",
376 |   "media_urls": [
377 |     "https://instagram.com/.../media1.jpg",
378 |     "https://instagram.com/.../media2.mp4"
379 |   ],
380 |   "title": "Post caption",
381 |   "author": "username",
382 |   "developer": "API Developer : @ISmartDevs",
383 |   "channel": "Updates Channel : @TheSmartDev"
384 | }
385 | 
386 | Response Example (Error):
387 | {
388 |   "status": "error",
389 |   "message": "URL Required To Download Your Desired Media!",
390 |   "media_urls": [],
391 |   "title": null,
392 |   "author": null,
393 |   "developer": "API Developer : @ISmartDevs",
394 |   "channel": "Updates Channel : @TheSmartDev"
395 | }
396 |                         
397 |

Note: Requires valid Instagram session cookies (cookies.txt) in Netscape format with sessionid and csrftoken.

398 |
399 |
400 |
401 |
402 |
403 | 404 | 405 |
406 |

Contribute 🌟

407 |
408 |

Contributions are welcome! Follow these steps to contribute:

409 |
    410 |
  1. Fork the repository. 🍴
  2. 411 |
  3. Create a new branch (git checkout -b feature-branch). 🌿
  4. 412 |
  5. Commit your changes (git commit -m 'Add new feature'). 💾
  6. 413 |
  7. Push to the branch (git push origin feature-branch). 🚀
  8. 414 |
  9. Open a Pull Request. 📬
  10. 415 |
416 |

Check out the repository on @TheSmartDevs.

417 |
418 |
419 | 420 | 421 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 528 | 529 | 530 | --------------------------------------------------------------------------------