taosecurity

Amazon Wishlist Scraper from https://codepen.io/merrimanbt/p

Mar 17th, 2020
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. /*
  2. === INSTRUCTIONS ===
  3.  
  4. 1. Open Amazon wishlist page
  5.  
  6. 2. Make sure all items are loaded. You may have to scroll for a long time if your list is long. Scroll until the **END OF LIST** marker is shown.
  7.  
  8. 3. Once all items are loaded, copy and paste the script below into the console, followed by hitting the `enter`/`return` key
  9. - On Chrome console can be found via: ` Ctrl + Shift + J (Windows / Linux)` or `Cmd + Opt + J (Mac)`
  10. - On Safari via: `Option + Cmd + C`
  11. - On Firefox via: `Ctrl + Shift + K` or `Cmd + Opt + K`
  12.  
  13.  
  14. 4. The page will turn into a formatted table of your items. You now have a few options:
  15. - select all the items w/ `ctrl + a` and paste it directly into an Excel sheet.
  16. - save the webpage as an HTML document/archive page/PDF (book marking will not work!)
  17. - other ideas I may not be thinking off
  18. */
  19.  
  20.  
  21. // Capture wishlist items
  22. var c = document.querySelectorAll(".g-item-sortable");
  23. var books = [];
  24. for (var i = 0; i < c.length; i++) {
  25. var book = {};
  26. var id = c[i].getAttribute("data-itemid");
  27. book["n"] = i;
  28. book["id"] = id;
  29. try {
  30. book["title"] = c[i].querySelector("#itemName_" + id).title;
  31. } catch (err) {
  32. book["title"] = "";
  33. }
  34.  
  35. try {
  36. book["link"] = c[i].querySelector("#itemName_" + id).href;
  37. } catch (err) {
  38. book["link"] = "";
  39. }
  40.  
  41. try {
  42. book["author"] = c[i].querySelector("#item-byline-" + id).innerText;
  43. } catch (err) {
  44. book["author"] = "";
  45. }
  46. try {
  47. book["image"] = c[i].querySelector("#itemImage_" + id + " img").src;
  48. } catch (err) {
  49. book["image"] = "";
  50. }
  51.  
  52. try {
  53. book["price"] = c[i].querySelector('.itemUsedAndNewPrice').innerText;
  54. } catch (err) {
  55. book["price"] = "";
  56. }
  57.  
  58. try {
  59. book["itemAddedDate"] = c[i]
  60. .querySelector("#itemAddedDate_" + id)
  61. .innerHTML.match(/\<\/span\>(.+)/)[1];
  62. } catch (err) {
  63. book["itemAddedDate"] = "";
  64. }
  65.  
  66. try {
  67. book["asin"] = JSON.parse(
  68. c[i].getAttribute("data-reposition-action-params")
  69. ).itemExternalId.match(/ASIN:(.+?)\|/)[1];
  70. } catch (err) {
  71. book["asin"] = "";
  72. }
  73. books.push(book);
  74. }
  75.  
  76. // Clear site
  77. document.body.innerText = "";
  78.  
  79.  
  80. // Build table w/ wishilist items
  81. function maketd(val) {
  82. var td = document.createElement("td");
  83. td.innerHTML = val.trim();
  84. return td;
  85. }
  86.  
  87. var table = document.createElement("table");
  88. table.style.margin="10px";
  89.  
  90. var head = document.createElement("tr");
  91. table.appendChild(head);
  92.  
  93. var head_dateAdded = document.createElement("th");
  94. head_dateAdded.innerText = "Date Added";
  95. head.appendChild(head_dateAdded);
  96.  
  97. var head_image = document.createElement("th");
  98. head_image.innerText = "Image";
  99. head.appendChild(head_image);
  100.  
  101. var head_title = document.createElement("th");
  102. head_title.innerText = "Title";
  103. head.appendChild(head_title);
  104.  
  105. var head_author = document.createElement("th");
  106. head_author.innerText = "Author";
  107. head.appendChild(head_author);
  108.  
  109. var head_asin = document.createElement("th");
  110. head_asin.innerText = "ASIN/ISBN";
  111. head.appendChild(head_asin);
  112.  
  113. var head_price = document.createElement("th");
  114. head_price.innerText = "Price";
  115. head.appendChild(head_price);
  116.  
  117. var head_link = document.createElement("th");
  118. head_link.innerText = "Link";
  119. head.appendChild(head_link);
  120.  
  121.  
  122.  
  123.  
  124.  
  125. for (var i = 0; i < books.length; i++) {
  126. let tr = document.createElement("tr");
  127. tr.appendChild(maketd(books[i].itemAddedDate));
  128. tr.appendChild(maketd(`<img src=${books[i].image}>`));
  129. tr.appendChild(maketd(books[i].title));
  130. tr.appendChild(
  131. maketd(books[i].author.replace("by ", "").replace(/\(.+?\)/, ""))
  132. );
  133. tr.appendChild(maketd(books[i].asin));
  134. tr.appendChild(maketd(books[i].price));
  135. tr.appendChild(maketd(`<a href='${books[i].link}'>Product Link</a>`));
  136. table.appendChild(tr);
  137. }
  138.  
  139. document.body.appendChild(table);
Add Comment
Please, Sign In to add comment