Example #1
0
        public void GetMetaNodesCollection_ValidHtml_ReturnHtmlNodeCollection()
        {
            var htmlDocument   = HtmlAgilityPackHelper.RetrieveHtml(ValidUrl);
            var nodeCollection = HtmlAgilityPackHelper.GetMetaNodesCollection(htmlDocument);

            Assert.IsNotNull(nodeCollection);
        }
Example #2
0
        private int GetKeywordOccurrencesFromHtmlDocument(string keyword, string url)
        {
            if (!IsUrlValid(url))
            {
                return(0);
            }

            var htmlDocument = HtmlAgilityPackHelper.RetrieveHtml(url);

            return(htmlDocument.Text.OccurrencesOf(keyword));
        }
Example #3
0
 public void RetrieveHtml_InvalidUrl_ThrowsException()
 {
     try
     {
         var htmlDocument = HtmlAgilityPackHelper.RetrieveHtml(InvalidUrl);
         Assert.Fail("An exception should have been thrown");
     }
     catch (Exception ex)
     {
         Assert.IsNotNull(ex);
     }
 }
Example #4
0
        private List <string> GetKeywordsFromUrl(string url)
        {
            if (!IsUrlValid(url))
            {
                return(null);
            }

            var htmlDocument = HtmlAgilityPackHelper.RetrieveHtml(url);
            var metaNodes    = HtmlAgilityPackHelper.GetMetaNodesCollection(htmlDocument);

            return(GetKeywordsFromMetaNodes(metaNodes));
        }
Example #5
0
        private List <KeywordDto> GetKeywordsOccurrencesFromHtmlDocument(IEnumerable <string> keywords, string url)
        {
            if (!IsUrlValid(url))
            {
                return(null);
            }

            var htmlDocument = HtmlAgilityPackHelper.RetrieveHtml(url);

            return((from keyword in keywords
                    let occurrenceCount = htmlDocument.Text.OccurrencesOf(keyword)
                                          select new KeywordDto()
            {
                Keyword = keyword,
                OccurenceCount = occurrenceCount
            }).ToList());
        }
Example #6
0
        public void RetrieveHtml_ValidUrl_ReturnHtmlDocument()
        {
            var htmlDocument = HtmlAgilityPackHelper.RetrieveHtml(ValidUrl);

            Assert.IsNotNull(htmlDocument);
        }