Scraping ASIN codes from Amazon is easier than you think. Okay, you can manually grab the ASIN codes from product pages URLs, but you can also get them from the search results too.

This can be done with an Amazon page, and a little XPath query. Fortunately, you can run XPath queries in Chrome, so you don’t have to install anything out of the ordinary.

Don’t worry if you’re not the most technically gifted, it’s easy to do, and I’ve included the code for you below!

Find an Amazon page to scrape

Open up Amazon, and a search for a keyword. Once the page has loaded up, you’ll see a bunch of items, and we’ll get to the scraping.

Make sure that the page that you’ve opened is a search results page. There’s no point mass scraping a single product page. Just copy the ASIN from the URL instead.

Note that each of the product listing element’s has a stored “data-asin”

Inspect element (right-click, click Inspect Element) on ones of the product listings, and you’ll see that there’s a “data-asin” attribute, with the product’s ASIN.

amazon inspect element data-asin
Inspect element on a product in the search results to find the data-asin attribute.

It might not be immediately obvious, but it’ll be there. Just goto the parent container of the HTML element.

Scrape ASIN codes with Chrome, jQuery & xPath

Next to the “elements” tab, in the inspect element panel, there’s a tab called “Console”.

You’ll now be able to type in Javascript queries and run them on the site by writing or pasting code in here.

$x('//@data-asin').map(function(v,i){return v.nodeValue})

You can paste in the above code, and it’ll scrape all the ASIN codes on the page.

Then, after you paste in the code, you’ll see a preview of the returned values. These should be the ASIN codes that you’re searching for.

Press enter and you’ll have a nicely formatted list of ASIN codes, freshly scraped for your usage!

If you have any questions, fire away in the comments below.

Until next time,
Josh

Leave a Reply
You May Also Like

A Handful of Niches for Early 2016

Every time the new year comes around there’s a whole host of…

The World Wide Web & The Oddly Named Things In It

The web is “an infrastructure of information combined and the network software…