Scrape Amazon ASIN: Super Simple XPath for Chrome Browser (No Downloads)


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.

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!

How to scrape Amazon ASIN codes using XPATH

Navigate to the Amazon page that you want 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.

Locate the data-asin attributes

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.

Open up Google Chrome’s console

Next to the “elements” tab, in the inspect element panel, there’s a tab called “Console”. Open this up. Here, you’ll able to run commands.

image 4

This is a really useful tool. If you don’t have Chrome, don’t worry. Most modern browsers allow you to access the console. For example, Edge, Firefox, and Opera, all have console access.

Run an XPath query to harvest the data-asin attributes

You’ll now be able to type in Javascript queries and run them on the site. The code below is an XPath query. It looks for all elements on a page that have the “data-asin” attribute. Then, it returns the value of the element.

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

You can paste it in your console. After pasting, it’s will scrape all the Amazon ASIN codes!

image 6

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 use!


Please enter your comment!
Please enter your name here