Exemplo n.º 1
0
        private QuoteHtmlData GetQuoteAndAuthorNode(HtmlDocument htmlDoc)
        {
            QuoteHtmlData quoteHtmlData = new QuoteHtmlData();

            quoteHtmlData.quotesHtml = htmlDoc.DocumentNode.Descendants("div")
                                       .Where(node => node.GetAttributeValue("class", "").Equals("quoteText")).ToList();

            quoteHtmlData.authorsHtml = htmlDoc.DocumentNode.Descendants("a")
                                        .Where(node => node.GetAttributeValue("href", "").Contains("/author/") && node.GetAttributeValue("class", "").Contains("authorOrTitle")).ToList();

            quoteHtmlData.numOfQuotes = quoteHtmlData.quotesHtml.Count;

            return(quoteHtmlData);
        }
Exemplo n.º 2
0
        private void GetQuotesAndAuthorsText(QuoteHtmlData quoteAuthorNode)
        {
            string[] delim = new string[] { "“", "”" };

            for (int j = 0; j < quoteAuthorNode.numOfQuotes; j++)
            {
                string extractedQuote = quoteAuthorNode.quotesHtml[j].InnerHtml.Split(delim, StringSplitOptions.None)[1].Replace("<br>", "\n");

                QuoteData quoteAuthorPair = new QuoteData
                                            (
                    Quote:  @"" + extractedQuote + "",
                    Author: quoteAuthorNode.authorsHtml[j].InnerText.Replace("&#39;", "'")
                                            );

                QuotesAndAuthorsText.Add(quoteAuthorPair);
            }
        }