Extract certain data from a webpage as it loads

redigerte September 2017 i Development Chrome


I am making a script to extract ALL ASIN from a page like below


I have tried

// ==UserScript==
// @name         v1script
// @namespace   v1script
// @version      0.1
// @description  asinscriptv1
// @author       me
// @include     *//*amazon.*/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// ==/UserScript==

(function() {
 'use strict';

 function clog(x){console.log(x);}

 var ids = [];
  var $me = $(this),
      $btn = $me.find("[data-result-rank=0]").first(),
      $asin = $btn.data("asin")  ;




but i am not able to get the value for each "data-asin" on the page.


  • redigerte September 2017 Chrome
    • $(".Container") returns no elements for me.
    • [data-result-rank=0] is not a valid selector, the value should be quoted.
    • There's only one element with data-result-rank=0 so you don't need =0 part if you want all ASIN.

    The entire code:

    // ==UserScript==
    // @name    ASIN scraper
    // @match   https://www.amazon.com/*
    // ==/UserScript==
    const asins = [...document.querySelectorAll('[data-asin]')].map(el => el.dataset.asin);

    To process page number navigation at the bottom of the amazon page, use a MutationObserver, because the page is changed in-place without being reloaded:

    // ==UserScript==
    // @name    ASIN scraper
    // @match   https://www.amazon.com/*
    // @require https://greasyfork.org/scripts/12228/code/setMutationHandler.js
    // ==/UserScript==
      selector: '[data-asin]',
      processExisting: true,
      handler: elements => {
        const asins = elements.map(el => el.dataset.asin);
  • The first code is working perfectly.

    But when we navigate between page numbers it doesn't capture the ASIN, tried using "MutationObserver" but still it can't get the value for each "data-asin"

    Further I forgot to add in my question, by current code we need to manually click page-1, page-2, page-3 etc to get the ASIN, I need this to be done with this script itself like "click" Next Page (selector "pagnNextString") get ALL ASIN,[copy ASIN to clipboard or store somewhere] again click Next Page and get ASIN and so on ...

  • In that case you'd be better off using amazon search API.

  • i am looking to do this via greasemonkey , with current code I can get ALL ASIN as required just needed to click " Next Page" with code and extract ASIN for other page however "MutationObserver" isn't working so stuck.
  • What? I'm not interested.

  • redigerte October 2017 Chrome
    thats fair @wOxxOm , I cannot force you :smile: I am trying hard to get my code working correctly, Thanks
  • redigerte January 2018 Default Browser
Logg inn eller Registrer deg for å kommentere.