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

C# 

Instagram user data scraper

Since my time was wasted, I am posting this. It will scrape the following information for a specified instagram username:
  • Amount of followers

  • Whether or not they are verified

  • Their username

  • Their description



InstagramUser.cs:
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InstagramScraper
{
    class InstagramUser
    {

        public bool isVerified;
        public int followers;
        public string username;
        public string description;

        public void parsePage(string ua, string user)
        {
            using (Request r = new Request(ua))
            {
                string response = r.requestString("https://instagram.com/" + user);
                parsePage(response);
            }
        }

        public void parsePage(string response)
        {
            //Verified
            string verified = "\"is_verified\":";
            if (response.Contains(verified))
            {
                int startIndex = response.IndexOf(verified);
                int endIndex = response.IndexOf(",", startIndex);
                string verifiedVal = response.Substring(startIndex + verified.Length, (endIndex - (startIndex + verified.Length)));
                isVerified = (verifiedVal == "true" ? true : false);
            }

            //Followers
            string follower = "\"followed_by\":{\"count\":";
            if (response.Contains(follower))
            {
                int startIndex = response.IndexOf(follower);
                int endIndex = response.IndexOf("}", startIndex);
                string follow = response.Substring(startIndex + follower.Length, (endIndex - (startIndex + follower.Length)));
                followers = Int32.Parse(follow);
            }

            //Username
            string name = "<meta property=\"og:url\" content=\"https://instagram.com/";
            if (response.Contains(name))
            {
                int startIndex = response.IndexOf(name);
                int endIndex = response.IndexOf("/", startIndex + name.Length);
                string n = response.Substring(startIndex + name.Length, (endIndex - (startIndex + name.Length)));
                username = n;
            }

            //Description
            string bio = "\"biography\":\"";
            if (response.Contains(bio))
            {
                int startIndex = response.IndexOf(bio);
                int endIndex = response.IndexOf("\",", startIndex + bio.Length);
                string desc = response.Substring(startIndex + bio.Length, (endIndex - (startIndex + bio.Length)));
                description = desc;
            }
        }
    }
}

Request.cs:
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace InstagramScraper
{
    class Request : IDisposable
    {
        private string useragent;
        private WebClient wc;

        public Request(string ua)
        {
            useragent = ua;
            wc = new WebClient();
            wc.Headers.Add("User-Agent", ua);
            wc.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            wc.Headers.Add("Accept-Language", "en-US,en;q=0.5");
            //wc.Headers.Add("Connection", "close");
            wc.Headers.Add("Cache-Control", "max-age=0");
        }

        public string requestString(string uri)
        {
            try {
                string resp = wc.DownloadString(@uri);
                return resp;
            }
            catch (Exception ex)
            {
                
                return ex.Message;
            }
        }

        public void Dispose()
        {
            wc.Dispose();
        }
    }
}

Usage:
Code
InstagramUser iu = new InstagramUser().parsePage("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)", "snoopdogg");
New to trading cryptocurrencies but don't know where to start? Join Binance here! Binance is my favourite exchange for cryptocurrencies w/ low fees.

[Image: 793854efd3c9ee7d90ddd413ae9deed6.png]
this one will help me mate thanks
The code is absolutely terrible
A ternary operator for a true/false condition? You do know that a condition is basically a function that returns true or false, right. And you should use properties instead of public fields. And your string parsing isn't bad, but I suggest using Regex for it next time. And the Request class is pretty bad if I may say so myself... also work on your naming conventions.


(Dec 18, 2016 09:06 AM)+Haze Wrote:  The code is absolutely terrible

How about you are not a cunt and tell him what is terrible or shut your mouth?
(Dec 18, 2016 09:32 AM)Ninja Wrote:  How about you are not a cunt and tell him what is terrible or shut your mouth?

How about you stop acting like you're the mod of this section? It's never going to happen.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
(Dec 18, 2016 09:32 AM)Ninja Wrote:  How about you are not a cunt and tell him what is terrible or shut your mouth?

Are you okay? Can you not tell by ops thread that it's likely the code was not written by him? It's likely he paid a freelancer to do it for him who didn't complete it so he just gave the code out, so you suggesting him ways to improve the code is pointless, not to mention half of what you said was nonsense.
(Dec 18, 2016 10:57 AM)+Haze Wrote:  Are you okay?
Yes.

(Dec 18, 2016 10:57 AM)+Haze Wrote:  Can you not tell by ops thread that it's likely the code was not written by him?

No.

(Dec 18, 2016 10:57 AM)+Haze Wrote:  not to mention half of what you said was nonsense.

So what exactly was nonsense. Point one thing out.


(Dec 18, 2016 09:42 AM)idb. Wrote:  How about you stop acting like you're the mod of this section? It's never going to happen.

Im not acting like the mod of this section, but telling someone his code is bad without telling him what is bad is a dick move.
(Dec 18, 2016 09:32 AM)Ninja Wrote:  A ternary operator for a true/false condition? You do know that a condition is basically a function that returns true or false, right. And you should use properties instead of public fields. And your string parsing isn't bad, but I suggest using Regex for it next time. And the Request class is pretty bad if I may say so myself... also work on your naming conventions.



How about you are not a cunt and tell him what is terrible or shut your mouth?

Are you new here?
Daily reminder to not necro threads
[Image: a2dac36451a435791d8ef98546adb8fc.png]

(Dec 18, 2016 09:32 AM)Ninja Wrote:  A ternary operator for a true/false condition? You do know that a condition is basically a function that returns true or false, right. And you should use properties instead of public fields. And your string parsing isn't bad, but I suggest using Regex for it next time. And the Request class is pretty bad if I may say so myself... also work on your naming conventions.



How about you are not a cunt and tell him what is terrible or shut your mouth?

I'm well aware of all of these changes by now - the thread is over a year old. I had written the code sloppily and quickly for a freelancing gig, and then I was promptly told to fuck off. I don't write IG bots usually, so it was of no use to me. I think originally I was going to make InstagramUser instantiated by name (hence its not static) but just didn't for whatever reason.
However, even though it's not needed, I do thank you for the feedback. I would have appreciated it if I hadn't improved since :p

(Dec 18, 2016 09:42 AM)idb. Wrote:  How about you stop acting like you're the mod of this section? It's never going to happen.

Constructive criticism is always nice - even if the code was made over a year ago. Stop trying to get your dick wet and let someone try to bring this section out of the deep shit it's in.

(Dec 18, 2016 10:57 AM)+Haze Wrote:  Are you okay? Can you not tell by ops thread that it's likely the code was not written by him? It's likely he paid a freelancer to do it for him who didn't complete it so he just gave the code out, so you suggesting him ways to improve the code is pointless, not to mention half of what you said was nonsense.

Incorrect. I wrote it over a year ago. In fact, the scenario is the other way around - I was being paid to do this, wrote some quick, sloppy concept code, and had no use for it after they told me to fuck off.

(Dec 18, 2016 11:35 AM)Ninja Wrote:  Im not acting like the mod of this section, but telling someone his code is bad without telling him what is bad is a dick move.

Precisely.
New to trading cryptocurrencies but don't know where to start? Join Binance here! Binance is my favourite exchange for cryptocurrencies w/ low fees.

[Image: 793854efd3c9ee7d90ddd413ae9deed6.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by BigFruitySep 2, 2021 09:09 AM 3 150 Sep 2, 2021 09:09 AM
Last Post: BigFruity
[Python] by kirmacoeaJul 14, 2021 10:46 AM 5 280 Jul 14, 2021 10:46 AM
Last Post: Coach Corey
[C#] by FatBurritoJul 9, 2021 12:32 PM 44 1,964 Jul 9, 2021 12:32 PM
Last Post: FatBurrito