Last active
July 19, 2023 07:38
-
-
Save pfreema1/113a6405e0dc28c971182cd5b110532a to your computer and use it in GitHub Desktop.
Get all amazon reviews on current page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
To use: | |
-open amazon product page | |
-click "see all reviews" and scroll to bottom of page to load all reviews | |
-copy and paste this code into console | |
-repeat on pages 2,3,4 etc | |
*/ | |
let allReviews = ""; | |
const scraper = function () { | |
const reviewEls = document.querySelectorAll('[data-hook="review"]'); | |
if (reviewEls.length === 0) { | |
console.error("no reviews found!"); | |
return; | |
} | |
reviewEls.forEach((reviewEl) => { | |
const csvRow = []; | |
const reviewTextEl = reviewEl.querySelector('[data-hook="review-body"]'); | |
if (!reviewTextEl) { | |
console.error("no review text el found"); | |
return; | |
} | |
allReviews += `\n\nREVIEW:`; | |
allReviews += `\n\n${reviewTextEl.innerText}`; | |
}); | |
}; | |
scraper(); | |
console.log(allReviews); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment