Easy Build Amazon ASIN Grabber with PHP and Curl

Surely you already familiar with words AMAZON ASIN ? yup, Amazon ASIN is a code for the item on Amazon’s website. For the players amazon affiliate, Collecting ASIN code takes a lot of time to get a lot of product on the Amazon website. Many software products are sold to take ASIN code automatically ( Or usually netter called it ASIN GRABBER ) and quickly on the Amazon site, but with constrained costs, we can not afford to buy the software.

In my first article, will discuss about how to build the Software to grab the Amazon ASIN using PHP and CURL.

Why use PHP CURL to build the amazon ASIN grabber?

According to php.net, curl is “ PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication. These functions have been added in PHP 4.0.2. ”. By using curl, we can take the element-element of a site and process it, If you need to learn more about PHP CURL, visit php.net.

Ok, let’s try to use php curl to take elements from the amazon website. with the following script.

Create CURL function as curl_url

And use this script to call curl_url function

The result is :

asin grabber curl php result

With use preg_match_all ( Perform a global regular expression match ) function, We can filter the html element, fit our purpose.

That function is filter the <a href> html element from amazon url

 The next step is filter string to get Amazon ASIN Product 

Change print_r($var.”\n”); with

Voila!! We Grab ASIN from amazon.com 😀

ASIN grabber resultWhat is syntax if ($result[4]==’dp’) { …. } for ?

After we got <a href> element from curl_url function, check the url . ASIN code is locate before the word ‘dp’ . An example from result

http://www.amazon.com/Apple-iPhone-5s-Gold-Unlocked/dp/B00F3J4E5U/ref=sr_1_1/181-6054500-5986120?s=electronics&ie=UTF8&qid=1406083079&sr=1-1&keywords=iphone+5s .

Split url into array with explode function :  $result=explode(“/”,$var); . Word ‘dp’ contained in array number 4 and ASIN code in array number 5. Filter array number 4 and grab ASIN code in array number 5.

Example :

It`s easy right ?  🙂   You can modify this script to your needs. Thank you for visiting my site .

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.


 Add your comment
  1. Hello Sigit.

    Thank you for sharing valuable tips on ASIN grabbing.
    I am having trouble producing successful result from the script given on this page, and I am glad if you could help me out.
    I simply copy and paste given script in the given order just like bellow. Do you see any false in it?

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.