From 771676889adec254ecda7bc716050130f42038a6 Mon Sep 17 00:00:00 2001 From: dotrahat <61520096+dotrahat@users.noreply.github.com> Date: Wed, 13 Jul 2022 01:26:26 +0500 Subject: [PATCH] Update Amazon.js - 2 Fixes 1. Selector of verified purchase badge is different on amazon than what is used in this package. So, I Updated Selector where it checks if purchase is verified while scraping reviews and now it gets it correctly. 2. "Get total number of reviews" didn't get the number correctly if there is a comma in number like 1,345. If comma exists, it only returns the number present before comma (1 in case of 1,345). I added replace function there to get rid of commas before parseInt uses it. So, After I Updated this code now it gets total number of reviews correctly. --- lib/Amazon.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Amazon.js b/lib/Amazon.js index c8a98a5..748c4cd 100755 --- a/lib/Amazon.js +++ b/lib/Amazon.js @@ -423,7 +423,7 @@ class AmazonScraper { /** * Get total number of reviews */ - this.reviewMetadata.total_reviews = parseInt($('.averageStarRatingNumerical').text(), 10); + this.reviewMetadata.total_reviews = parseInt($('.averageStarRatingNumerical').text().replace(/,/ig, ''), 10); const reviewsList = $('#cm_cr-review_list')[0].children; let scrapingResult = {}; @@ -533,7 +533,7 @@ class AmazonScraper { * If purchase is verified */ for (let key in scrapingResult) { - const search = $(`#${key} [data-reftag="cm_cr_arp_d_rvw_rvwer"]`); + const search = $(`#${key} [data-hook="avp-badge"]`); scrapingResult[key].verified_purchase = false; try {