Exemplo n.º 1
0
        public async Task <List <int> > GetPageRanks(string searchString, string expectedText, int maxResultsToSearch)
        {
            if (searchStrategy == null)
            {
                throw new ApplicationException("Please set a strategy before getting page ranks.");
            }

            List <int> pageRanks         = new List <int>();
            int        currentRank       = 1;
            int        currentSearchPage = 1;

            while (!string.IsNullOrEmpty(searchStrategy.GetSearchPageUrl(currentSearchPage)) && currentRank <= maxResultsToSearch)
            {
                var searchResultLinks = await htmlReader.GetAttributeValues(
                    searchStrategy.GetSearchPageUrl(currentSearchPage),
                    searchStrategy.GetHtmlDomSearchXPath(),
                    "href");

                foreach (var link in searchResultLinks)
                {
                    if (link.Contains(expectedText))
                    {
                        pageRanks.Add(currentRank);
                    }

                    currentRank++;

                    if (currentRank > maxResultsToSearch)
                    {
                        break;
                    }
                }

                currentSearchPage++;
            }

            return(pageRanks);
        }