It’s been a long time not make an article about amazon affiliate site, I will share a script, how to grab ASIN code on amazon sites easily. With my script, you can easily get thousands of ASIN in minutes.
Preparation
1. Download simple_html_dom class here as tool.
2. Copy asingrabber class below and save it as asingrabberclass.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <?php /* * Sigit Prasetya Nugroho https://seegatesite.com * * Amazon asin grabber class, how to grab amazon asin code with easy way. */ class asingrabber{ function get_content($url) { $content = @file_get_contents($url); if($content) { $hasil = $content; } else { $hasil ='false'; } return $hasil; } function get_asin($content) { require_once('simple_html_dom.php'); $xml = new simple_html_dom(); $xml->load($content); $asin=''; $hasil = @$xml->find('li[data-asin]'); $jum = count($hasil); for ($i=0; $i < $jum ; $i++) { $asin .= $hasil[$i]->getAttribute('data-asin').","; } return $asin; } } ?> |
3. Create a php file to experiment using asingrabberclass to grab thousands of ASIN on the amazon site. Copy this script below
1 2 3 4 5 6 | require_once('asingrabberclass.php'); $url='amazon site'; // example : http://www.amazon.com/s/ref=nb_sb_noss/189-8301552-0738035?url=search-alias%3Daps&field-keywords=iphone+6 $amazon = new asingrabber; $content = $amazon->get_content($url); $asinlist = $amazon->get_asin($content); echo $asinlist; |
It’s very easy to use. The example above is basic using asingrabberclass.php script. I will show a more complex example how to grab thousands ASIN use asingrabberclass.php. Copy the script below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <html> <head> <meta charset="utf-8"> <title>Grab ASIN from amazon</title> </head> <body> <h2>Grab asin from amazon by <a href='https://seegatesite.com'>seegatesite.com</a></h2> <form method="post" action="" > <table style="border:0px"> <tr> <td>Url</td> <td> : <input type="text" name="url" placeholder="Example : http://www.amazon.com/s?keywords=iphone" size="100" /></td> </tr> <tr> <td>Page</td> <td> : <input type="text" size="3" name="page" value="10" /></td> </tr> <tr> <td colspan="2"> <hr> <input type="submit" name="submit" value="Grab Asin" id="submit"></td> </tr> </table> </form> <?php if(isset($_POST['submit'])) { echo " <hr> Result : </br>"; echo ' <div id="progress" style="width:500px;border:1px solid #ccc;"></div> '; echo ' <div id="information" style="width"></div> '; require_once('asingrabberclass.php'); $url=$_POST['url']; $page=$_POST['page']; $asinlist=''; for($i=1;$i<=$page;$i++) { $percent = intval($i/$page * 100)."%"; echo '<script language="javascript"> document.getElementById("progress").innerHTML=" <div style=\"width:'.$percent.';background-color:#ddd;\"> </div> "; document.getElementById("information").innerHTML="Page : '.$i.' processed."; </script>'; $newurl=trim($url).'&p='.$i; $amazon = new asingrabber; $content = $amazon->get_content($newurl); $asinlist .= $amazon->get_asin($content); echo str_repeat(' ',1024*64); flush(); sleep(0.005); } $count=count(explode(",",$asinlist)); echo "finish grab $count ASIN ! "; echo "<textarea rows='12' cols='50'>".$asinlist."</textarea>"; } ?> </body> </html> |
Watch the following video snippets how to grab asin with asingrabberclass.php.
Next time i will share my amazon class script to get amazon product detail with API. 🙂
Thank you so much for your helpful site. I tried your Amazon Asin Grabber, but unfortunately the tool does not seem to work properly. I tried to grab asins from amazon.com but somehow no data is being pulled in.
okay thank you. Not all products ASIN permitted to be offered by Amazon. So not all products can be taken.but I’ll check back in my code 🙂 thanks
Thanks for fixing your grabber tool! What was the problem? Did amazon change the website structure?
No, you can use my amazon ASIN Code grabber more powerfully for WordPress plugin here https://seegatesite.com/free-amazon-asin-grabber-plugin-and-tutorial/
Terima kasih script grabbernya, tapi saya mau tanya mas.
kenapa waktu saya jalankan diserver (pake share hosting) sering error “operation timed out” , kalau ga salah share hosting kan memberikan limit buat menjalankan script 30 detik kan.
bagaimana cara mengatasinya mas?
satu lagi pertanyaannya mas, bagaimana caranya kalau script ini digabung dengan Ajax seperti tools mas yang Amazon product scraper yang ini https://seegatesite.com/tools/amazon_scraper.php
Terima kasih sebelumnya mas
1.mengatasi timeout tambahkan kode berikut di header anda
[php]
ini_set(‘max_execution_time’, 7000);// silahkan sesuaikan dengan waktu yang diinginkan
[/php]
2. Silahkan kirim parameter yang dibutuhkan melalui ajax..dan tampilkan result valuenya..
[php]
var value = {
param1: var_param1,
param2: var_param2,
…..
};
$.ajax(
{
url : "xxxxxx.php", // url server amazon script anda
type: "POST",
data : value,
success: function(data, textStatus, jqXHR)
{
var data = jQuery.parseJSON(data);
//tampilkan hasilnya
},
error: function(jqXHR, textStatus, errorThrown)
{
}
});
[/php]
semoga membantu