juliusgeorge / instascrapper
A PHP package for scraping Instagram data.
Requires
- guzzlehttp/guzzle: ^7.9
- illuminate/container: ^12.8
- php-webdriver/webdriver: ^1.15
This package is auto-updated.
Last update: 2025-05-09 10:39:13 UTC
README
Overview
This project is an Instagram scraper designed to extract publicly available data from Instagram profiles, posts, and other accessible endpoints. It is intended for educational and research purposes only.
Features
- Extract post details (captions, likes, comments, etc.).
Requirements
- PHP 8.2 or higher
- Required libraries (install via
requirements.txt
):illuminate\container
guzzlehttp
php-webdriver\webdriver
Installation
- With composer:
composer require juliusgeorge/instascrapper
Usage
This package requires you to authenticate with instagram There are two ways of doing that
-
Via cookie Login to instagram grab the required cookies (rur,mid,sessionid,ig_id,ds_user_id,csrftoken) create an array of cookiename/value pair i.e
[ 'rur' => 'rur value', 'csrftoken' => 'csrftoken value', 'mid' => 'mid value', 'ig_id' => 'ig_id value', 'ds_user_id' => 'ds_user_id value', 'sessionid' => 'sessionid value' ]
after that call the generateAuthCookie static method of the InstaAuth\Auth class use InstaAuth\Auth;
$cookieAuth = Auth::generateCookieAuth($the_array)
Authenticate the scrapper using
Scrapper::cookieAuth($cookieAuth);
you can also generate a cookie auth token by providing your password and email|username
$auth = new Auth(); $cookieAuth = $auth->login('your email|username', 'your password');
use the cookie auth like in above step to authenticate
-
Scrapping comments: Before scrapping you need to authenticate, you can do that using the steps above Scrapping comments is pretty straight forward:
use InstaAuth\Auth; use InstaScrapper\Scrapper; use InstaScrapper\CommentScrapper; //authenticate the scrapper, we will be using cookie authentication here $cookie = [ 'rur' => 'rur value', 'csrftoken' => 'csrftoken value', 'mid' => 'mid value', 'ig_id' => 'ig_id value', 'ds_user_id' => 'ds_user_id value', 'sessionid' => 'sessionid value' ] Scrapper::cookieAuth(Auth::generateCookieAuth($cookie)); $commentScrapper = new CommentScrapper(); //pass in data to the comment scrapper using the with method $commentScrapper->with([ 'shortcode' => 'the instagram post shortcode', 'max_comment' => 'maximum number of comment to scrape' ]); $comments = $commentScrapper->scrape();
Disclaimer
This project is for educational purposes only. Scraping data from Instagram may violate their terms of service. Use responsibly and ensure compliance with applicable laws and regulations.
License
This project is licensed under the MIT License.