Scrape Instagram Followers | Extract Follower Data (2021) 
Tags: python, php, github
Published: 2021-03-05 07:31:12


**Important note**: Please be advised that automatically scraping follower data from Instagram is against their terms of service.

This is just an educational resource and for those of you who don’t have the time, resources, and want to be 100% on the legal side of things, [get in touch with Influencers Club](https://influencers.club/?utm_source=dev.to&utm_medium=scrape-insta-followers) and just buy email addresses from Instagram followers.

A lot of you want to know how to scrape data from your Instagram followers or anyone else's followers (*cough-competitors-cough*).

The reason being, it's an awesome way to get contact information like emails and phone numbers from a targeted audience. 

In this guide I'll share how you can scrape follower data yourself or completely outsource the scraping. 

##What Kind of Data You Can Scrape From Instagram?##

First things first, other than email addresses and phone numbers what other data you can extract from one Instagram account?

• Instagram Bio
• Number of Followers
• Location (10% of all users have country/city/street)
• Instagram Username
• Instagram Category (1 out of 1500)
• Number of Posts 
• Whether it's a business or a regular Instagram account

All of these data points will help you further analyze your database. For example if you want to find influencers among your followers (or competitors) you can simply sort your dataset by number of followers. That way you'll instantly see which Instagram users are popular and can be used to spread the word about your brand. 

##How to find emails and phone numbers from Instagram followers##

Few people know this but 30-40% of all Instagram users have their contact information right on their profile. 

Some of them add it willingly and some not...let me explain. 

There are two ways to find an email address or phone number on Instagram:

1. Instagram Biography
10% of all users intentionally add their contact details in their bio. Businesses, influencers and even regular users hope someone will reach out to them when they leave their email and contact number in bio. 

2. Instagram Business Accounts
Another 30% of all Instagram users have a so-called Instagram business account. With this type of profile they access additional statistics about their followers such as engagement %. 

However, what they (probably) don't know is that when creating a business account they also agree to make their personal contact information publicly available. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8194lqknm9qocvzuwa28.jpg)

##How to Instantly Get Data From Instagram Followers?##

There are a lot of data providers that collect Instagram user data and can scrape anyone's Instagram followers instantly. 

Before I continue explaining how you can do this yourself I want to explain why is sometimes better to simply outsource the scraping. 

I use this [Instagram email scraper](https://influencers.club/?utm_source=dev.to&utm_medium=scrape-insta-followers) because all of their data is validated upon scraping and they offer advanced targeting options like gender, age, location, interest. 

Here's why that's important:

###Why you need additional targeting?###
Although scraping Instagram followers is pretty targeted you still end up with a lot of people that are not relevant to your business. 

• 10% or 90 million Instagram profiles are fake accounts
• A lot of people will simply don't fall in your ideal niche (no gender, location, age or other types of targeting)

And if you plan on scraping emails for cold email marketing then this will negatively affect your campaigns i.e. very high bounce rates.


###Why you must clean the scraped data?###

Web-scraping means a lot of trash in your net. Some examples would be:

• Spam-traps
• Catch all emails
• Fake emails

Here's how this affects your plans:

Scraped email lists from Instagram can be used in two ways - either for cold emailing or using them as custom audiences in Facebook Ads. 

When you create your cold email campaign and reach out to so many invalid emails, there's a good chance your company domain will end up in SPAM. This means that even regular emails will be considered spam and not reach the desired destination. 

Or, if you import the list as Custom Audiences, Facebook will notice that a lot of your contacts are invalid which may result in permanent ban. 

**That's why the [Instagram scraper](https://influencers.club/2020/10/08/instagram-scraper/?utm_source=dev.to&utm_medium=scrape-insta-followers) I use also validates the emails and offers additional targeting like gender, age, location or emails based on keywords in user bio.**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8qgtlne3bg1l40v9dj89.jpg)

##How to Scrape Instagram Follower Data For Free?##

If you have less than 1000 followers you can extract data manually. Note that to see more information on a profile you need to visit all users with the Instagram application i.e. from a mobile device. 

Collect the data by copy-pasting it in a spreadsheet.

PS. I really don't recommend visiting more than 1k profiles manually (at least not with your personal profile) because you will get your account suspended.

##Building an Instagram Follower Scraper with Python and GitHub##

Python is the best way to scrape anything really. 

Extracting data from Instagram followers with Python comes down to two simple things. 

1. Scraping the usernames (or user IDs) that follow a given profile (yours, your competitor’s followers etc), hashtag or location (yes you can do that too)
2. Scraping additional details (email, category, etc) for all usernames/ids collected



###Extract Instagram Followers (User IDs) List##

If you only want to scrape follower usernames, here's a code sample by @tonoli (Github).

```
from datetime import datetime
from modules import compare
from modules import file_io
from modules import stats

from modules.scraper import Scraper
from modules.utils import ask_input, ask_multiple_option


groups = ['followers', 'following']

# Ask for input
target = ask_input('Enter the target username: ')
group = ask_multiple_option(options = groups + ['both']);
print('\nEnter your Instagram credentials')
username = ask_input('Username: ')
password = ask_input(is_password = True)

def scrape(group):
    differs = False
    scraper = Scraper(target)
    startTime = datetime.now()

    scraper.authenticate(username, password)
    users = scraper.get_users(group, verbose=True)
    scraper.close()

    last_users = file_io.read_last(target, group)
    if last_users:
        differs = bool(compare.get_diffs(users, last_users))

    if (differs or not last_users):
        file_io.store(target, group, users)
    # Stats
    stats.numbers(len(users), scraper.expected_number)
    if (differs): stats.diff(users, last_users)
    print('Took ' + str(datetime.now() - startTime))

if (group == 'both'):
    for group in groups:
        scrape(group)
else:
    scrape(group)
```

This is enough to extract the followers of specific Instagram account. 

One thing worth mentioning is that profiles with huge follower base will be harder to scrape with this method (Instagram is pretty strict with call-limits). But for a small account, it should do the job. 

Here's all you'll need to execute this:
• Python 3
• PIP
• Chrome installed (Selenium uses the chromedriver contained in the drivers folder)
• and, Instagram credentials to log in

###Scraping additional follower details (email, category, etc)###

If you only needed to scrape list of Instagram usernames, that follow a specific account, then you’ll be done with the first part. But if you want to market to those people, then you’ll need to scrape additional details, like email addresses, phone numbers, category of the profile etc.

This is a bit harder to do as you’ll need Instagram accounts and log them through the mobile API. Here is a sample on how to do that with the browser, but again, you are limited and PLEASE don’t do any scraping with your main Instagram account:

```
from requests import get
from bs4 import BeautifulSoup
import sys
import re
import json
from datetime import datetime

URL = 'https://www.instagram.com'

def get_data(username):
    url = '%s/%s/' % (URL, username)
    page = get(url, timeout=5)
    soup = BeautifulSoup(page.content, 'html.parser')
    data = soup.find_all('meta', attrs={'property': 'og:description'})
    photo = soup.find_all('meta', attrs={'property': 'og:image'})
    text = data[0].get('content').split()
    retext = re.findall(
        '<script type="text\/javascript">([^{]+?({.*profile_pic_url.*})[^}]+?)<\/script>', str(soup))[0][1]
    jsontext = json.loads(retext)['entry_data']['ProfilePage'][0]
    print(jsontext)
    media_likes = 0
    media_comments = 0
    media_views = 0
    media_count = 0
    media_videos = 0
    media_list = []
    for media in jsontext['graphql']['user']['edge_owner_to_timeline_media']['edges']:
        media_count += 1
        media_likes += media['node']['edge_liked_by']['count']
        media_comments += media['node']['edge_media_to_comment']['count']
        if media['node']['is_video']:
            media_videos += 1
            media_views += media['node']['video_view_count']
            media_list.append({
                'id': '2042452950535483363',
                'img_url': media['node']['thumbnail_src'],
                'date_posted': datetime.fromtimestamp(media['node']['taken_at_timestamp']),
                'likes': media['node']['edge_liked_by']['count']  
            })
        else:
            media_list.append({
                'id': '2042452950535483363',
                'img_url': media['node']['thumbnail_src'],
                'date_posted': datetime.fromtimestamp(media['node']['taken_at_timestamp']),
                'likes': media['node']['edge_liked_by']['count'],
            })
    media_video_like_engagement = 0
    media_video_comment_engagement = 0
    if media_videos != 0:
        media_video_like_engagement = (
            ig_tv_likes / ig_tv_videos) / (ig_tv_views / ig_tv_videos)

    return ....
```
Full code available [here](https://github.com/tonoli/instagram-followers-scraper/blob/master/main.py).

If you don’t want to bother with that, you can just upload the list of usernames you already got to [this API](https://api.influencers.club/?utm_source=dev.to&utm_medium=scrape-instagram-followers) and enrich it with the email addresses. It’s free to sign up and you’ll also get 1500 credits so use it to speed up the process. 

##Get Instagram follower data (no-code)##

If you have no previous experience with Python but want to export a list of your followers (without contact data) you can use IGExport. If you are targeting less than 500 followers you can export the list for free. The max amount of followers you can download is 50k. 

And for those of you who also want to get valid & targeted emails and phone numbers from anyone's followers, visit Influencers Club.