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
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.
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.
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 can paste it in your console. After pasting, it’s will scrape all the Amazon ASIN codes!
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!