示例#1
0
        private FollowerState GetFollowerState(string followerNickname, ref FiltersStatus filtersStatus)
        {
            webDriver.Navigate().GoToUrl(@"https://www.instagram.com/" + followerNickname);
            string pageHTML = webDriver.PageSource;

            if (pageHTML.Contains("Страница не найдена") || pageHTML.Contains("Sorry, this page isn't available.") || pageHTML.Contains("Контент недоступен"))
            {
                return(new FollowerState()
                {
                    LeaveInList = false
                });
            }
            else
            {
                IWebElement description;
                try
                {
                    description = webDriver.FindElement(By.ClassName("-vDIg"));
                    foreach (string stopWord in filtersStatus.StopWordsFilter.Split(','))
                    {
                        if (description.Text.Contains(stopWord))
                        {
                            return(new FollowerState()
                            {
                                LeaveInList = false
                            });
                        }
                    }
                }
                catch
                {
                }
            }
            return(new FollowerState
            {
                FollowerObject = new Follower
                {
                    AvatarEnable = filtersStatus.AvatarEnableFilter ? GetAvatarEnable() : true,
                    FollowersCount = filtersStatus.FollowersCountFilter ? GetFollowersCount() : 0,
                    Nickname = followerNickname,
                    PostsCount = filtersStatus.PostsCountFilter ? GetPostsCount() : 0,
                    SubscriptionsCount = filtersStatus.SubscriptionsCountFilter ? GetSubscriptionsCount() : 0
                },
                LeaveInList = true
            });
        }
示例#2
0
        public void FilteringProccess(ref FiltersStatus filtersStatus,
                                      string baseToFilterFilepath, string baseFilepathAfterFiltering,
                                      FilteringParameters filteringParameters)
        {
            StreamWriter streamWriter = new StreamWriter("temp.txt");
            //сообщить о получении базы
            List <FollowerState> followersList = new List <FollowerState>();

            foreach (var followerNickname in Parsers.ReadListOfStringFromFile(baseToFilterFilepath))
            {
                if (!string.IsNullOrEmpty(followerNickname))
                {
                    FollowerState followerState = GetFollowerState(followerNickname, ref filtersStatus);
                    followersList.Add(followerState);
                    if (!followerState.LeaveInList)
                    {
                        streamWriter.WriteLine(followerNickname + "\t\tEmpty page\n");
                    }
                }
            }
            followersList = (from follower in followersList where follower.LeaveInList select follower).ToList();//removing empty links
            if (filtersStatus.AvatarEnableFilter)
            {
                foreach (var followerState in followersList)
                {
                    Filters.AvatarFilter(followerState);
                }
                foreach (var followerNickname in (from follower in followersList where !follower.LeaveInList select follower.FollowerObject.Nickname).ToList())
                {
                    streamWriter.WriteLine(followerNickname + "\t\tNo avatar\n");
                }
                followersList = (from follower in followersList where follower.LeaveInList select follower).ToList();
            }
            if (filtersStatus.FollowersCountFilter)
            {
                foreach (var followerState in followersList)
                {
                    Filters.FollowersCountFilter(followerState,
                                                 filteringParameters.FollowersMinCount, filteringParameters.FollowersMaxCount);
                }
                foreach (var followerNickname in (from follower in followersList where !follower.LeaveInList select follower.FollowerObject.Nickname).ToList())
                {
                    streamWriter.WriteLine(followerNickname + "\t\tFollowers count\n");
                }
                followersList = (from follower in followersList where follower.LeaveInList select follower).ToList();
            }
            if (filtersStatus.PostsCountFilter)
            {
                foreach (var followerState in followersList)
                {
                    Filters.PostsCountFilter(followerState, filteringParameters.PostsMinCount, filteringParameters.PostsMaxCount);
                }
                foreach (var followerNickname in (from follower in followersList where !follower.LeaveInList select follower.FollowerObject.Nickname).ToList())
                {
                    streamWriter.WriteLine(followerNickname + "\t\tPosts count\n");
                }
                followersList = (from follower in followersList where follower.LeaveInList select follower).ToList();
            }
            if (filtersStatus.SubscriptionsCountFilter)
            {
                foreach (var followerState in followersList)
                {
                    Filters.SubscriptionsCountFilter(followerState, filteringParameters.SubscriptionsMinCount, filteringParameters.SubscriptionsMaxCount);
                }
                foreach (var followerNickname in (from follower in followersList where !follower.LeaveInList select follower.FollowerObject.Nickname).ToList())
                {
                    streamWriter.WriteLine(followerNickname + "\t\tSubscriptopns count\n");
                }
                followersList = (from follower in followersList where follower.LeaveInList select follower).ToList();
            }
            streamWriter.Close();
            List <string> followers = (from folwer in followersList select folwer.FollowerObject.Nickname).ToList();//ответ на один из методов выше

            Parsers.WriteListOfStringToFile(followers, baseFilepathAfterFiltering);
        }