Sebastien Horin Sebastien Horin - 1 year ago 239
Javascript Question

Scraping data from Instagram

I actually just need the followers count of a public account,
for example

The new Instagram's API rules are very strict (and discussed):
It's now impossible to access public content for most of common apps. You need a public_content scope that is not granted to normal app (?!)

public_content: This permission (public_content) is only granted to
apps that enable brands, advertisers, broadcasters and publishers to
discover public content. We do not grant access to apps that do not
fall into these categories. Please review our documentation
( for more information.

So I decided to scrape the data from Instagram

An option is to use file_get_contents() (PHP) and it works but it loads all the site from my server and it's pretty heavy. So my first idea was to use YQL. I use it for Twitter and works well, but when I scrape data from Instagram I get nothing:*%20from%20html%20where%20url%3D''&

Answer Source

I took a look into the page you submitted, it's not that heavy, considering that you won't load images or process js. While inspecting I found out that they have a json where they store their data.

.... "followed_by": {"count": 924725}

I didn't had time to test this, but it should work, or at least you get the point of using it. CURL may be a better option because it can handle multithreaded requests.

$url = '';
$str = file_get_contents($url);
$count = 0;
if(preg_match('#followed_by": {"count": (.*?)}#', $str, $match)) {
     $count = $match[1]; // get the count from Regex pattern
} echo $count;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download