Scrape Instagram Followers

Hey there, I´m searching for a way to display my Instagram followers on the frontend, to keep an eye on them. Found out it could be possible with the Scrape sensor, but because I´m more beginner in this material, I don´t know if its possible to scrape the follower number from a Instagram Website (like this one here for an example: https://www.instagram.com/fcbayern/?hl=de)

Thanks in advance

You can use the following configuration:

sensor:
  - platform: scrape
    resource: https://www.instagram.com/panbachi.de/
    name: instagram followers
    select: 'meta[name="description"]'
    attribute: content
    value_template: '{{ value.split(" ")[0] }}'
1 Like

thank you very much! just tried it out and it works perfect! one last question, I want to see the full follower number, right now i see for example 97.8K but is it possible to see the detail like 97827?

I think, that this is not possible. I can’t find the full count in the HTML sourcecode. Only the short one.

Found there is real number in the html… not sure how to extract it

<span class="g47SY " title="47,367">47.3k</span>

@napsio u got any way around this ?

The problem is, that the HTML element is generated by JavaScript and so it is not possible to scrape it from the HTML code.

My solution to scrape my instagram follower:

- platform: scrape
  resource: https://www.instagram.com/niefuend/
  name: Niefuend_instagram_follower
  select: '[type="application/ld+json"]'
  unit_of_measurement: 'follower'
  value_template: '{{ value_json.mainEntityofPage.interactionStatistic.userInteractionCount }}'
  headers:
    User-Agent: Mozilla/5.0
1 Like

Thanks for sharing! It seemed to work for a while but since a few weeks I get only a “unknown” value back. Do you know why?

I had the same problem.
Now i use a real Useragent.

https://www.whatismybrowser.com/detect/what-is-my-user-agent

sorry but can you explain that a bit more? Do I have to install a new useragent?

i changed the useragent to my real browser UA

headers:
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36

ah ok, I tried this, but there is still no change :frowning: Could it be any browser, or from the machine Home Assistant is running?

is there any reliable solution for instagram followers? couldnt get it to work :confused:

I just got it to work on first try… This is what i have in my config:

sensor:
  - platform: scrape
    resource: https://www.instagram.com/smarthomesimon/
    name: Isnstagram followers
    select: 'meta[name="description"]'
    attribute: content
    value_template: '{{ value.split(" ")[0] }}'

thats the same code i have. it doesnt work for me:

Logger: homeassistant.components.scrape.sensor
Source: components/scrape/sensor.py:147
Integration: scrape (documentation, issues)
First occurred: 13:45:08 (104 occurrences)
Last logged: 14:36:39

Unable to extract data from HTML for Instagram

Same issue here, anybody that has a solution or an tip on how to ‘debug’ the scraper?

I’m having a similar issue. I’ve tried to set the user agent, but no luck. The HTML returned by the page is still valid and matches our patterns. I can’t tell if IG have some javascript setting this data after page load, or if the page request is being blocked in it’s entirety. We need more detailed logs from the GET request being made by the scraper module to know for sure. A response code or message would help a lot, but I don’t know how to get that data from HA.

I think the problem is that Instagram tries to block all kind of scraping, like someone who made a python Instagram scraper reported: https://chris-greening.github.io/instascrape/2021/01/07/important-planned-features-for-january.html

I think one solution could be to add a session_id in the header, but I still could not find out how to do that.

Another (paid) way would be to use the Instagram API. Since Instagram gives you a API key only for professional use (as far as I know), I use https://smartmetrics.co to grab my Instagram Followers, but also other details about my profile (like comments, story views etc.) But it costs 10 Euros a month, and it only updates every 60 minutes

you can get the data from just calling https://www.instagram.com/USERNAME/?__a=1
it isnt json, but i think there could be a method to extract the “edge_followed_by”:{“count”: and you would get the followers.

i tried to get an instagram api but its complicated as fuck. never got it working.

hi, the result is WELCOME, how resolve ?

thanks

1 Like