Amazon Reviews Exporter for Multiple ASINs

Export Amazon reviews for multiple ASINs, sorted by star rating, with automatic pagination

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/490561/1347388/Amazon%20Reviews%20Exporter%20for%20Multiple%20ASINs.js

  1. // ==UserScript==
  2. // @name Amazon Reviews Exporter for Multiple ASINs
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Export Amazon reviews for multiple ASINs, sorted by star rating, with automatic pagination
  6. // @author You
  7. // @match https://www.amazon.com/*
  8. // @grant GM_xmlhttpRequest
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js
  10. // @license MIT
  11. // ==/UserScript==
  12. // @require https://update.gf.qytechs.cn/scripts/490561/1347386/Amazon%20Reviews%20Exporter%20for%20Multiple%20ASINs.js
  13. (function() {
  14. 'use strict';
  15.  
  16. let asins = [];
  17. let currentASINIndex = 0;
  18. let currentStar = 5;
  19. let allReviews = [];
  20.  
  21. function addStartButton() {
  22. const button = document.createElement('button');
  23. button.textContent = 'Start Reviews Export';
  24. button.style.position = 'fixed';
  25. button.style.top = '20px';
  26. button.style.right = '20px';
  27. button.style.zIndex = '1000';
  28. button.style.padding = '10px';
  29. button.style.fontSize = '16px';
  30. button.style.cursor = 'pointer';
  31. button.onclick = startReviewsExport;
  32. document.body.appendChild(button);
  33. }
  34.  
  35. function startReviewsExport() {
  36. const userInput = prompt("Enter ASINs separated by commas (e.g., ASIN1,ASIN2):");
  37. if (userInput) {
  38. asins = userInput.split(',').map(asin => asin.trim());
  39. currentASINIndex = 0;
  40. allReviews = [];
  41. processNextASIN();
  42. }
  43. }
  44.  
  45. function processNextASIN() {
  46. if (currentASINIndex < asins.length) {
  47. currentStar = 5;
  48. processStarRating(asins[currentASINIndex]);
  49. } else {
  50. exportToExcel(allReviews);
  51. }
  52. }
  53.  
  54. function processStarRating(asin) {
  55. if (currentStar >= 1) {
  56. let pageNumber = 1;
  57. const reviewPageUrl = `https://www.amazon.com/product-reviews/${asin}/ref=cm_cr_getr_d_paging_btm_next_3?ie=UTF8&reviewerType=all_reviews&sortBy=recent&pageNumber=${pageNumber}&filterByStar=${currentStar}_star`;
  58. fetchAndProcessReviews(reviewPageUrl, pageNumber, asin);
  59. } else {
  60. currentASINIndex++;
  61. processNextASIN();
  62. }
  63. }
  64.  
  65. function fetchAndProcessReviews(url, pageNumber, asin) {
  66. GM_xmlhttpRequest({
  67. method: "GET",
  68. url: url,
  69. onload: function(response) {
  70. const parser = new DOMParser();
  71. const doc = parser.parseFromString(response.responseText, "text/html");
  72. const reviews = doc.querySelectorAll('.review');
  73. if (reviews.length > 0) {
  74. reviews.forEach(review => {
  75. const reviewText = review.querySelector('.review-text').textContent.trim();
  76. allReviews.push({ ASIN: asin, star: currentStar, text: reviewText });
  77. });
  78. pageNumber++;
  79. const nextPageUrl = `https://www.amazon.com/product-reviews/${asin}/ref=cm_cr_getr_d_paging_btm_next_3?ie=UTF8&reviewerType=all_reviews&sortBy=recent&pageNumber=${pageNumber}&filterByStar=${currentStar}_star`;
  80. fetchAndProcessReviews(nextPageUrl, pageNumber, asin);
  81. } else {
  82. currentStar--;
  83. processStarRating(asin);
  84. }
  85. }
  86. });
  87. }
  88.  
  89. function exportToExcel(reviews) {
  90. const worksheet = XLSX.utils.json_to_sheet(reviews);
  91. const workbook = XLSX.utils.book_new();
  92. XLSX.utils.book_append_sheet(workbook, worksheet, "Reviews");
  93. XLSX.writeFile(workbook, 'Amazon_Reviews.xlsx');
  94. }
  95.  
  96. addStartButton();
  97. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址