AmazonScrape.Scraper.DecodeHTML C# (CSharp) Method

DecodeHTML() public static method

Decodes the HTML-encoded sections of the supplied string
public static DecodeHTML ( string html ) : string
html string HTML-encoded string
return string
        public static string DecodeHTML(string html)
        {
            string result = "";
            try
            {
                result = HttpUtility.HtmlDecode(html);
            }
            catch
            {
                string msg = "Unable to decode HTML: " + html;
                throw new ArgumentException(msg);
            }

            return result;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Extracts the product's name from a single product's html
        /// </summary>
        /// <param name="itemHtml">Single product result html</param>
        /// <returns>Name of product</returns>
        public static string GetProductName(string itemHtml)
        {
            string productNamePattern = @"(?<= title="").*?(?="" )";
            string match = GetSingleRegExMatch(itemHtml, productNamePattern);

            if (match.Length == 0)
            {
                return(null);
            }

            string productName = Scraper.DecodeHTML(match);

            return(productName);
        }