Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Instagram Private/Public Photo Scraper

Scrape photos off public and private Instagram profiles.

[Image: 036edea7ab.gif]

Note: Scraping private profiles require you to login with an account that follows the user.

Sauce: https://github.com/arcanecfg/Instagram-Private-Scraper

For the glory of humanity
Nice release appreciated, thanks!!!
Thanks Arcane  ❤️
You‘re teh man, appreciate that you share the source.

I'm currently selling my Pokétrainer's balls to raise money
[Image: jesX9Uy.gif]
Pi-ka? Pi ... Pikachu !
Continue with good posts...this is really good share
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58
Here is my 2 cents. This is in no way meant to bring you down. I love the contribution and I want to help you learn and improve, so please takes this the positive way.

The constant class contains global constants. This is not necessarily bad, but there is more info on why to avoid global variables here. This applies a bit to static variables/classes as well.

This makes no sense. You are saying:
if whatever = true return true if false return false.
why not return the condition instead? Saves 4 lines of code.

And consider using using statements instead, as they tend to look cleaner, and because if an exception is thrown in your code than the object is not disposed. You could also solve this with a finally block after the catch.
More info on the using block here.
More info on the finally block and disposing here.

The account class; making everything public and static, and not using properties can be considered bad practice by many. If you want to expose a field publicly, then use a property. And by not making it static you could drag and drop the account class and the login function from the other class in another project and get going right away, without needing to modify much.
More info on auto-properties here and here.

In the main class you have a huge function called FetchPosts. This is also bad practice, as if you want to follow OOP strictly, you should segment functionality. Have functions/classes solely for one responsibility (single responsibility principle). This will make the code easier to read and maintain and debug. There is a general, unwritten, rule of thumb; functions cannot be larger than your screen size.
More info on the SOLID principles here.

You use multiple WebClient instances, and never dispose them. You could have declared one single WebClient in the class so that every function can utilize it (except when threading). And for threading, everytime you download a picture you declare a new WebClient instance and never dispose of it. Consider giving each thread its own WebClient instance that they can re-use.

Deserializing JSON to dynamics, when done quite often, decreases performance as dynamics have an overhead. Consider using a website like json2csharp that converts the json to classes for you, or use the Special Paste option in Visual Studio to do the same. It will generate a RootObject and all other necessary classes, and you can then deserialize the JSON to the RootObject. If you have a lot of classes (when handling large JSON for example), just group them all together in a single .cs file.

You parse text from the JSON, and then deserialize part of the JSON. Why not deserialize all of it and then get what you need from the class instances it returns?

And finally, booleans by default are false when instantiated (unless you set them to true when instantiating). So "bool flag = false;" can be shortened to "bool flag;".
Code
if (HTTPMethods.POST("username=" + InstagramAccount.username + "&password=" + InstagramAccount.password, InstagramAccount.cookies, csrfToken, "\"authenticated\": true", Constants.Referer))

Use URL encoding.
The pagination is now broken after an Instagram update.

The /?__a=1&max_id=end_cursor is deprecated. If anyone knows how the new pagination works, feel free to update this.

For the glory of humanity
The thing is you can't name this a private account scrapper,if i had an account following it then it'd be easy,so just call it a public account scrapper :P
check https://stackoverflow.com/a/49341049
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
(Sep 3, 2018 12:04 PM)HFDone Wrote:  check https://stackoverflow.com/a/49341049

I already figured out that endpoint, but the 'queryhash' value remains constant for sometime and varies after a while.

For the glory of humanity
media - query_hash=298b92c8d7cad703f7565aa892ede943
https://github.com/mineur/instagram-pars...d-query-id
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
(Sep 4, 2018 10:28 AM)HFDone Wrote:  media - query_hash=298b92c8d7cad703f7565aa892ede943
https://github.com/mineur/instagram-pars...d-query-id

That's cool, but it's still part of the querystring. Is it possible to grab it programmatically?

For the glory of humanity
Not trying to disregard your project but instaloader exists for a reason and is actively maintained, https://github.com/instaloader/instaloader

I just wished there would be something like that for facebook, piece of crap website
(Sep 10, 2018 03:17 AM)Decim Wrote:  That's cool, but it's still part of the querystring. Is it possible to grab it programmatically?

if you login using cookie and form data you should be good

the query looks like
https://www.instagram.com/graphql/query/...&variables={"tag_name":"tag_name","first":12,"after":"end_cursor"}
if you not login you will get error
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by FatBurritoJul 9, 2021 12:32 PM 44 1,964 Jul 9, 2021 12:32 PM
Last Post: FatBurrito
[.NET] by mzabossSep 21, 2017 02:03 PM 11 493 Sep 21, 2017 02:03 PM
Last Post: Synfuls
[C#] by ChickendipperDec 19, 2016 08:37 AM 8 668 Dec 19, 2016 08:37 AM
Last Post: Chickendipper