AmazonScrape.Scraper.LoadReviewHistogram C# (CSharp) Method

LoadReviewHistogram() public static method

Given a product's unique Amazon ID, loads the review distribution histogram. Much faster than an entire pageload for detailed review info.
public static LoadReviewHistogram ( string asin ) : string
asin string
return string
        public static string LoadReviewHistogram(string asin)
        {
            Uri reviewHistogramPopupURL = new Uri(Constants.REVIEW_HISTOGRAM_URL + asin);

            return Scraper.CreateHttpRequest(reviewHistogramPopupURL);
        }

Usage Example

Example #1
0
        /// <summary>
        /// Given a specific product result html, provides the review histogram
        /// html. Used for obtaining review count and review distribution.
        /// </summary>
        /// <param name="itemHtml"></param>
        /// <returns>string html of review histogram</returns>
        public static string GetReviewHistogramHtml(string itemHtml)
        {
            // To get the review information without loading an entire new page,
            // we will call the review histogram popup URL instead of the main URL
            // We need the ASIN of the product to make the call, which is in the same
            // DIV tag as the product result #:
            string productASINPattern = @"(?<=name="").*?(?="">)";

            string match = GetSingleRegExMatch(itemHtml, productASINPattern);

            // Occassionally Amazon adds attributes to the end of the tag, so
            // find the end of attribute containing the ASIN (should be the first
            // double quote we encounter).
            int endAttributeIndex = match.IndexOf('"');

            if (endAttributeIndex > 0)
            {
                // Truncate anything after
                match = match.Substring(0, endAttributeIndex);
            }

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

            // With the product ASIN, make the httprequest to get the review popup data
            return(Scraper.LoadReviewHistogram(match));
        }