[SCRIPT] Scrape E-Mails from Instagram Bios [BUILD E-MAIL LISTS]

Hello BHW community,

I have a script that uses Instagrams API to pull e-mails from instagram bios and it works really well, you can specify your target market so it pulls from the right profiles. Successfully got thousands of e-mails after running this for just a few hours.

I would like to make this available for the BHW community to use. My script runs off of API and therefore needs an API key. How do I make it so anyone at anytime can use my script - without an API key? Is this possible?

Also if possible:
1) I coded this in PHP, but do not know how to build this out into a nice User Interface. Any resources on building a UI will be very much appreciated.
2) How do I license the program so my script can't be stolen/cracked?

Thank you!

I made a simple Instagram PHP library for you. Add a simple for loop, a delay, and your scraper is done. :)
It uses Instagram.com(web interface) as its API, so you don't need any API key. It can scrape information about a user, a photo, a hashtag(list of top and recent photos). It is possible to use a proxy(example: "new InstagramScraper('231.52.125.62:8080')").

Get it here: http://pastebin.com/raw/FyMg0nE2
Or copy from here:
PHP:
<?php
error_reporting(E_ALL ^ E_NOTICE);
set_time_limit(0);
header('Content-Type: text/html; charset=utf-8');

class InstagramScraper
{
    protected $proxy = null;
    protected $timeout = 5;
    protected $headers = [
        'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Accept-Language' => 'en-US',
        'User-Agent' => 'Mozilla/5.0 (Windows NT 6.4; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2225.0 Safari/537.36',
        'Connection' => 'close'
    ];

    public function __construct($proxy = null, $timeout = null)
    {
        if ($proxy !== null)
            $this->proxy = $proxy;

        if ($timeout !== null)
            $this->timeout = $timeout;
    }

    public function getHeaders()
    {
        return $this->headers;
    }

    public function setHeader($key, $value)
    {
        $this->headers[$key] = $value;
    }

    public function removeHeader($key)
    {
        unset($this->headers[$key]);
    }

    public function getTimeout()
    {
        return $this->timeout;
    }

    public function setTimeout($timeout)
    {
        $this->timeout = $timeout;
    }

    public function getProxy()
    {
        return $this->proxy;
    }

    public function setProxy($proxy)
    {
        $this->proxy = $proxy;
    }

    public function getMediaFromHashtag($hashtag)
    {
        $response = $this->request('http://instagram.com/explore/tags/' . urlencode($hashtag) . '/');
        $sharedData = $this->extractSharedData($response);

        if (isset($sharedData['entry_data']) && isset($sharedData['entry_data']['TagPage'])) {
            $photos = [
                'top' => $sharedData['entry_data']['TagPage'][0]['tag']['top_posts']['nodes'],
                'recent' => $sharedData['entry_data']['TagPage'][0]['tag']['media']['nodes']
            ];

            return $photos;
        } else {
            throw new Exception('Couldn\'t get media from #' . $hashtag);
        }

        return [];
    }

    public function getMedia($mediaCode)
    {
        $response = $this->request('https://instagram.com/p/' . $mediaCode . '/');
        $sharedData = $this->extractSharedData($response);

        if (isset($sharedData['entry_data']) && isset($sharedData['entry_data']['PostPage'])) {
            $media = $sharedData['entry_data']['PostPage'][0]['media'];

            return $media;
        } else {
            throw new Exception('Couldn\'t get media ' . $mediaCode);
        }

        return [];
    }

    public function getProfile($username)
    {
        $response = $this->request('https://instagram.com/' . $username . '/');
        $sharedData = $this->extractSharedData($response);

        if (isset($sharedData['entry_data']) && isset($sharedData['entry_data']['ProfilePage'])) {
            $profile = $sharedData['entry_data']['ProfilePage'][0]['user'];

            return $profile;
        } else {
            throw new Exception('Couldn\'t get profile ' . $username);
        }

        return [];
    }

    protected function extractSharedData($response)
    {
        $searchFor = '">window._sharedData = ';
        if (strpos($response, $searchFor) !== false) {
            $parts = explode($searchFor, $response, 2);
            if (count($parts) === 2) {
                $parts = explode(';</script>', $parts[1], 2);
                if (!empty($parts[0])) {
                    $sharedData = @json_decode($parts[0], true);

                    if ($sharedData) {
                        return $sharedData;
                    }
                }
            }
        }

        return [];
    }

    protected function request($url, $method = 'GET', $data = null)
    {
        if ($data !== null) {
            $header['Content-Type'] = 'application/x-www-form-urlencoded';
        }

        $headers = [];
        foreach ($this->headers as $key => $value) {
            $headers[] = $key . ':' . $value;
        }

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_VERBOSE, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
        if ($this->proxy !== null) {
            $proxyPath = $this->proxy;
            if (strpos($proxyPath, '@') !== false) {
                list($proxyAuth, $proxyPath) = explode('@', $proxyPath);
                curl_setopt($ch, CURLOPT_PROXYPWD, $proxyAuth);
            }

            curl_setopt($ch, CURLOPT_PROXY, $proxyPath);
            if (is_numeric($proxyPath[0]))
                curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
        }
        if (strtolower($method) === 'post') {
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);

        return $response;
    }
}

// Create a new scraper
$scraper = new InstagramScraper();

try {
    // Get a list of photos from hashtag
    $photos = $scraper->getMediaFromHashtag('fashion');
    // Get detailed information about the first photo
    $photo = $scraper->getMedia($photos['recent'][0]['code']);
    // Get uploader's profile
    $profile = $scraper->getProfile($photo['owner']['username']);

    // Show profile's biography
    echo 'Biography of ' . $profile['username'] . ': ' . $profile['biography'];
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
 
Last edited:
Back
Top