1

I'm trying to pull the view count from a video on Instagram. This is the video: https://www.instagram.com/p/BxEApSqgNJn/

I have been able to get Youtube and Facebook views, but struggling with Instagram.

I have used the following Formula to pull data from Facebook Video:

=IFERROR(LEFT(IMPORTXML(H28,"//*[@data-tooltip-position='below']"),LEN(IMPORTXML(H28,"//*[@data-tooltip-position='below']"))-5),"0")

H28 is the Link

It should show the views the video has achieved, in this case... 351,271 views as of May 14, 2019.

player0
  • 124,011
  • 12
  • 67
  • 124
Dan Shaikh
  • 13
  • 3

2 Answers2

1

How about this workaround for retrieving the value? In this workaround, the value is retrieved from the data which is preparing for Javascript. The data is updated when the page is loaded, and retrieved using a xpath, and the value is retrieved using a regular expression. So I used this method. The modified formula is as follows. Please think of this as just one of several answers.

Sample formula:

In this sample formula, https://www.instagram.com/p/BxEApSqgNJn/ is put in the cell "A1".

=REGEXEXTRACT(IMPORTXML(A1,"//script[@type='application/ld+json']"),"userInteractionCount"":""(\d+)")
  1. Retrieve data using the xpath of //script[@type='application/ld+json'] with IMPORTXML().
  2. Retrieve the value using the regular expression of userInteractionCount"":""(\d+) with REGEXEXTRACT().

Result:

enter image description here

References:

If I misunderstood your question and this was not the result you want, I apologize.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • This workaround isn't working for me today. Please confirm if it's still working for you. – Rubén Jan 02 '23 at 07:28
  • 1
    @Rubén Thank you for replying. About `This workaround isn't working for me today. Please confirm if it's still working for you.`, although when I posted this answer, the formula worked, it is considered that the specification of the server side has been changed. I deeply apologize that I cannot continue to confirm whether the specification of the server side is changed. In the current stage, how about using API? It seems that when the Instagram graph api is used, the view count can be retrieved. https://developers.facebook.com/docs/instagram-api/reference/ig-media/insights?locale=en#metrics – Tanaike Jan 02 '23 at 08:15
  • 1
    Thank you very much for your reply and suggestion Tanaike. It looks that whenever there is a API the best will be to use it instead of current Google Sheets built-in functions. – Rubén Jan 02 '23 at 08:22
  • 1
    @Rubén I think that if the API has already been implemented in the site, when the API is used, the script might be able to become simple rather than the value being directly retrieved from the HTML data and/or the value intercepted during the displaying HTML is constructed. – Tanaike Jan 02 '23 at 08:29
0

unfortunately, that won't be possible because Instagram is controlled by JavaScript and Google Sheets can't understand/import JS. you can test this simply by disabling JS for a given link and you will see a blank page

player0
  • 124,011
  • 12
  • 67
  • 124