I want to use Google Scripts to import the number of ratings of an Amazon product for each star rating (x 5-star-ratings, y 4-star-ratings, z 3-star-ratings, etc.).
I use the script below on this webpage (already filtered for 1 star ratings) but I get "No ratings found"
function getRatings(url) {
var content = UrlFetchApp.fetch(url).getContentText();
var match = content.match(/<div data-hook="cr-filter-info-review-rating-count" class="a-row a-spacing-base a-size-base".*>([^<]*)<\/div>/);
return match && match [1] ? match[1] : 'No ratings found';
}
Instead, if I use this other script on the same page I am able to gather the total number of ratings (but not only the 1 stars).
function totalReviewcount(url) {
var content = UrlFetchApp.fetch(url).getContentText();
var match = content.match(/<span class="a-size-base a-color-secondary".*>([^<]*)<\/span>/);
return match && match [1] ? match[1] : 'No reviews yet';
}
Can anyone point me in the right direction?
Thanks