Recent

Author Topic: Instagram scraper class  (Read 4740 times)

Renat.Su

  • Full Member
  • ***
  • Posts: 181
    • Renat.Su
Instagram scraper class
« on: July 14, 2018, 04:51:09 pm »
I use my small class to work with instagram. I want to note that this is not an Instagram API wrapper to which access is unrealistic, and besides the functionality of this API is limited. This is namely the scraper/parser, which uses unofficially an instagram server to obtain various information about accounts, likes, comments stories etc.
Are there any forum users who also work with Instagram or suddenly start working with it? My class is ready and ready to use. Initially I didn't think to share the class but if someone is also willing to put effort into the development of this class it would be possible to cooperate or maybe I even opened the code under some open license as a separate module

alexone

  • New Member
  • *
  • Posts: 17
Re: Instagram scraper class
« Reply #1 on: November 19, 2018, 10:46:43 pm »
I would like to write a simple follower count -- engagement program for one of my accounts. very interested in your class.

Renat.Su

  • Full Member
  • ***
  • Posts: 181
    • Renat.Su
Re: Instagram scraper class
« Reply #2 on: November 20, 2018, 08:03:11 am »
Well, today I will try to upload the repository to GitHub. Update my here.

Renat.Su

  • Full Member
  • ***
  • Posts: 181
    • Renat.Su
Re: Instagram scraper class
« Reply #3 on: November 20, 2018, 11:43:54 am »
So, this is a link to the repository https://github.com/Al-Muhandis/fp-instagramscrapper. Suggestions and improvements are welcome.

The demo shows an example of getting the values you need https://github.com/Al-Muhandis/fp-instagramscrapper/tree/master/demo

With the same class, you can get a bunch of other properties, media content, comments, stories, and highlights

alexone

  • New Member
  • *
  • Posts: 17
Re: Instagram scraper class
« Reply #4 on: November 20, 2018, 07:07:25 pm »
thank you very much.

crack81

  • New Member
  • *
  • Posts: 12
Re: Instagram scraper class
« Reply #5 on: November 20, 2018, 10:15:35 pm »
Thanks for share, I will try it more later and give you my feedback.
Regards...

alexone

  • New Member
  • *
  • Posts: 17
Re: Instagram scraper class
« Reply #6 on: November 21, 2018, 09:28:43 pm »
did exactly whay I wanted -- follower returns when called. thank you! Now to learn this and get egagement rates

Renat.Su

  • Full Member
  • ***
  • Posts: 181
    • Renat.Su
Re: Instagram scraper class
« Reply #7 on: November 22, 2018, 10:28:03 am »
Now to learn this and get egagement rates
If you want to calculate the egagement rate, you will need at least the number of likes and comments for a particular post (media). So instead
Code: Pascal  [Select][+][-]
  1. Instagram.ParseGetAccount(S)
in demo You should use
Code: Pascal  [Select][+][-]
  1. Instagram.ParseGetPost(S);
where S - media ID like BR4ulEOAong in media url, after then You can get
Code: Pascal  [Select][+][-]
  1. LikesCount:=Instagram.Likes;
  2. CommentCount:=Instagram.CommentCount;

You can also parse by simply specifying the url, for example
 
Code: Pascal  [Select][+][-]
  1.  
  2.   if not Instagram.IsInstagramUrl(AUrl) then
  3.   begin
  4.     Writeln('It is not Instagram url!');
  5.     Exit;
  6.   end;
  7.   LikesCount:=Instagram.Likes;
  8.   CommentCount:=Instagram.CommentCount;  
  9.  

alexone

  • New Member
  • *
  • Posts: 17
Re: Instagram scraper class
« Reply #8 on: November 25, 2018, 11:07:16 pm »
working perfect --- thank you.
Is there a method or function to return the last x numbers of posts to finalize er function? Say the last 12 posts and then I can do the er math..I cannot find any such items.

Renat.Su

  • Full Member
  • ***
  • Posts: 181
    • Renat.Su
Re: Instagram scraper class
« Reply #9 on: November 26, 2018, 11:25:18 am »
1st method. Like this below. In the JSON object jsonUser data is stored
Code: Pascal  [Select][+][-]
  1. ... ... ...
  2.   var
  3.     ANode: TJSONObject;
  4. ... ... ...
  5.   begin
  6. ... ... ...
  7.     if Instagram.ParseGetAccount(AccountUsername) then
  8.     begin
  9. ... ... ...
  10.       for i:=0 to Instagram.Images.Count-1 do
  11.       begin
  12.         ANode:= TJSONObject(Instagram.Images.Objects[i]);
  13.         ِAShortCode:= ANode.Strings['shortcode'];
  14.         ALikes:=ANode.Objects['edge_media_preview_like'].Integers['count'];
  15.         ACommentCount:=ANode.Objects['edge_media_to_comment'].Integers['count'];
  16. // You can parse any other media post properties from Instagram JSON Object from media JSON node
  17. ... ... ...
  18.       end;
  19.       for i:=0 to Instagram.Videos.Count-1 do
  20.       begin
  21.         ANode:= TJSONObject(Instagram.Videos.Objects[i]);
  22.         ِAShortCode:= ANode.Strings['shortcode'];
  23.         ALikes:=ANode.Objects['edge_media_preview_like'].Integers['count'];
  24.         ACommentCount:=ANode.Objects['edge_media_to_comment'].Integers['count'];
  25. // You can parse any other media post properties from Instagram JSON Object from media JSON node
  26. ... ... ...
  27.       end;
  28.  
  29.     end;
  30. ... ... ...
  31.   end;
You can also work directly with the received jsonUser object, which contains an array of the last 12 media
Code: Pascal  [Select][+][-]
  1. ANode:=Instagram.jsonUser.Objects['edge_owner_to_timeline_media'].arrays['edges'].Objects[i].Objects['node']
The advantage of the 1st method:
+ no authorization is required,
+ less likely to be banned.
Drawback:
-only a maximum of 12 latest media return
« Last Edit: November 26, 2018, 01:12:03 pm by Renat.Su »

Renat.Su

  • Full Member
  • ***
  • Posts: 181
    • Renat.Su
Re: Instagram scraper class
« Reply #10 on: November 26, 2018, 11:35:54 am »
2nd method. Use getMediasByUserID...
 Earlier, I was being parsed media did used a method getMediasByUserID. But it doesn't seem to be working right now. I don't test. And it requires authentication (I'm not sure).

alexone

  • New Member
  • *
  • Posts: 17
Re: Instagram scraper class
« Reply #11 on: November 26, 2018, 12:50:05 pm »
instagram lately has been hit or miss even my phone app -- servers go down nearly every day,, it may not be your code just them. Thank you .

Renat.Su

  • Full Member
  • ***
  • Posts: 181
    • Renat.Su
Re: Instagram scraper class
« Reply #12 on: November 26, 2018, 01:36:14 pm »
By itself, I do not like instagram )

Added two test procedures. With its will be clear

 

TinyPortal © 2005-2018