Well, this time I will share about how to scraping amazon products using Amazon API. Many new amazon players are still confused how amazon API worked to scraping amazon product. I dont suggest you to do the screen scraping, Because is not permissable. Scrap amazon products using the API is a legal way. Beside legal, its more easy to use than screen scraping.
Who still confused about scraping amazon products using APIs can see the video snippet below
Table of Contents
- 1 To build Scraping Amazon script, you need to prepare.
- 1.1 1. Get your amazon public key and amazon private key from aws.amazon. Read here for more info.
- 1.2 2. Build Function in PHP to get Product Advertising API URL
- 1.3 For scraping amazon xml data and how to arrange the data so that look elegant, i will discuss on the next article, if you have a question please comment below 🙂 .
To build Scraping Amazon script, you need to prepare.
1. Get your amazon public key and amazon private key from aws.amazon. Read here for more info.
2. Build Function in PHP to get Product Advertising API URL
I got the function from this site, visit there if you need to learn more. I do a little modification to be easy to use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | function aws_signed_request($region, $params, $public_key, $private_key) { $method = "GET"; $host = "ecs.amazonaws.".$region; $uri = "/onca/xml"; $params["Service"] = "AWSECommerceService"; $params["AWSAccessKeyId"] = $public_key; $params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z",time()); //may not be more than 15 minutes out of date! $params["Version"] = "2009-03-31"; ksort($params); $canonicalized_query = array(); foreach ($params as $param=>$value) { $param = str_replace("%7E", "~", rawurlencode($param)); $value = str_replace("%7E", "~", rawurlencode($value)); $canonicalized_query[] = $param."=".$value; } $canonicalized_query = implode("&", $canonicalized_query); $string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query; $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True)); $signature = rawurlencode($signature); $request = "http://".$host.$uri."?".$canonicalized_query."&Signature=".$signature; return $request; } |
Call that function with this syntax below
1 2 3 4 5 6 7 8 9 10 11 | $parameters=array( 'Operation' =>'ItemLookup' , 'ItemId' =>$sku , // change $sku with ASIN code 'AssociateTag' =>$tag, //Your AssociateTag url 'ResponseGroup' =>'Large' , //Small, Medium, Large or SellerListing ); $public_key =$pub_key; // Change with your public key $private_key=$priv_key; // Change with your private key $ext='com'; //extension of server, see data.php ksort($parameters); // To shorting variable $parameters $A=aws_signed_request($ext,$parameters,$pub_key,$priv_key); // Call aws_signed_request |
The results of the $A variable is you will get Product Advertising API URL like
If you get results as above, you've managed to get Amazon product XML. With a few additions and looping statements in the script above you will get thousands of Amazons data , within a matter of hours.
You can combine with my ASIN GRABBER SCRIPT to get a reliable program. See and try my example here.
Thanks for this article. I am still stumped on how to get the public/private keys. I ‘thot’ I had them, but they appear to be certificate signature files (20 lines), not a normal 20-40 character string.
I got them here:
https://console.aws.amazon.com/iam/home?region=us-west-2#security_credential
sory i dont understand what you mean ? but i created new public and private key from your link, it is successful
can this script be used to fetch all the amazon products?
This script can fetch the amazon products that are allowed by amazon API