PCRemote.Core.Utilities.InstagramGraber.Grab C# (CSharp) Method

Grab() public method

public Grab ( string user, int count = 10 ) : List
user string
count int
return List
        public List<string> Grab(string user, int count = 10)
        {
            bool hasNext;
            var firstPage = true;
            var nextUrl = string.Empty;

            var result = new List<string>();
            var web = new HtmlWeb();
            var countIndex = 0;
            do
            {
                if (firstPage)
                {
                    firstPage = false;
                    nextUrl = string.Format("http://web.stagram.com/n/{0}?vm=grid", user);
                }

                var doc = web.Load(nextUrl);
                var images = doc.DocumentNode.SelectNodes("//img[@src]");

                foreach (var att in images.Select(image => image.Attributes["src"].Value).Where(att => att.Contains("_6")))
                {
                    result.Add(att.Replace("_6", "_7"));
                    countIndex++;

                    if (count != 0 && countIndex >= count )
                        return result;
                }

                var nextNode = doc.DocumentNode.SelectSingleNode("//a[@rel='next']");
                if (nextNode != null)
                {
                    hasNext = true;
                    nextUrl = string.Format("http://web.stagram.com{0}&vm=grid", nextNode.Attributes["href"].Value);
                }
                else
                {
                    hasNext = false;
                }

            } while (hasNext);

            return result;
        }

Usage Example

Example #1
0
        public void grab_test()
        {
            var graber = new InstagramGraber();
            var results = graber.Grab("burberry");

            foreach (var result in results)
            {
                Console.WriteLine(result);
            }
        }
All Usage Examples Of PCRemote.Core.Utilities.InstagramGraber::Grab
InstagramGraber