Previously I made an article about Quickly Build Amazon ASIN Grabber with Simple Html DOM , For easy to use, I created this script into the WordPress plugin. With this plugin, you have your amazon asin grabber. Besides giving this plugin to you for free, i share tutorial how to build Amazon Asin Grabber as wordpress plugin too :).
Okay, we lets start asin grabber tutorial 🙂 (NOTE : This is my first wordpress plugin 🙂 )
Table of Contents
Build Amazon Asin Grabber WordPress Plugin
Create WordPress Plugin Header
To create WordPress plugin, we need to create Standard Plugin Information header. This header lets the WordPress recognize if your plugin is exists, add the code below to the main plugin file.
Without the plugin header, your plugin will never be activated and running ( Read more how to create wordpress plugin here wordpress.org ). Create new php file, give name as asin-grabber.php
1 2 3 4 5 6 7 8 | /* Plugin Name: Amazon Asin Grabber Plugin URI: https://seegatesite.com Description: With Amazon Asin Grabber plugin, you can grab unlimited Amazon Asin Code. Make sure your hosting powerful, before you grab thousands of ASIN :) Version: 1.0 Author: Sigit prasetya nugroho Author URI: https://seegatesite.com/ */ |
Create new add_action function
Add add_action function to locate your plugin’s menu
1 2 3 4 | add_action('admin_menu', 'lokasi_menu'); function lokasi_menu(){ add_options_page('Amazon ASIN Grabber', 'Amazon ASIN Grabber', 'manage_options', 'asin-grab', 'asin_grabber_func'); } |
- admin_menu is the name of add_action.
- lokasi_menu is my add_action value.
- To put location of plugins in the settings menu we need a function add_options_page.
Create Asin Grabber function
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 | <?php function asin_grabber_func() { if (isset($_POST['submit'])) { if(!empty($_POST['asin_txt']) && !empty($_POST['page']) ) { if (filter_var($_POST['asin_txt'], FILTER_VALIDATE_URL) === FALSE) { ?> <button onclick="history.go(-1);">Back </button><br /> <?php die('Not a valid URL Address'); } $hasil=graburl(urlencode($_POST['asin_txt']),$_POST['page']); echo $hasil; }else { ?> <button onclick="history.go(-1);">Back </button><br /> <?php die('Please fill URL Address or Page count'); } } else { ?> <div class="wrap"> <form method="post" action="<?php echo asin_back();?>"> <h2>Amazon Asin Grabber</h2> <table> <tr> <td>Url</td> <td> : <input type="text" id="asin_txt" name="asin_txt" placeholder="Example : http://www.amazon.com/s?keywords=iphone" size="100" /></td> </tr> <tr> <td>Page</td> <td> : <input type="text" size="3" id="page" name="page" value="10" /></td> </tr> <tr> <td><input type="submit" name="submit" id="submit"></td> </tr> </table> </form></div> <?php } |
We create HTML Form in asin_grabber_func(), we need 2 parameters to grab asin from amazon (amazon url and page count).
1 | action="<?php echo asin_back();?>" |
Create asin_back() function
1 2 3 | function asin_back(){ return admin_url("options-general.php?page=asin-grab"); } |
Create graburl() function
garburl() function used to grab asin.
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 | function graburl($url,$page) { $html = file_get_html(trim(urldecode($url))); $retval=''; $no=1; $asin_area=''; $cnt=0; foreach($html->find('a') as $element) { foreach ($element->find('span') as $node1) { if ($node1->class=='lrg bold') { foreach ($node1->find('text') as $node) { if ($node->parent() === $node1 && strlen($t = trim($node->plaintext))) { $url = $element->href; $hasil=explode("/",$url); if (count($hasil)>=5) { if ($hasil[4]=='dp') { $asin_area=$asin_area.$hasil[5]."\n"; $asin=$hasil[5]; $cnt++; } } $no++; } } } } } $retval='<h2>Result : </h2><table><tr><td>Grab :</td><td>'.$cnt.' Asin</td></tr><tr><td colspan=2><textarea style="float:left;" rows="20" cols="12">'.$asin_area.'</textarea></td></tr></table><button onclick="history.go(-1);">Grab More </button><br/> * If you need tutorial how to create this plugin visit my site <a href="https://seegatesite.com" target="_blank">Seegatesite</a>'; return $retval; } |
Voila, Your asin grabber plugin has been created 🙂
Download amazon asin grabber WordPress Plugin
If you need to download example amazon asin grabber , click link below
[sociallocker id=”58″]
[/sociallocker].
or download here https://wordpress.org/plugins/amazon-asin-grabber/
Nice! Thanks for this addon..
One thing.. when I tried.. If I ask 10 page.. no problem.. But if I ask 50 or more.. I get no result.. Page come empty.. Probably something about a too long request.. I think an option “how many page per request” should be needed..
Hello mike, Thank you very much for your response and great request.. i will update my plugin as soon as as soon as possible 🙂
whenever i enter url and click submit it gives me 404 error
hello,
Can you give a more detailed explanation?
thx you 🙂
Hey Sigit,
Great resources for building API based plugins on your site.
I wanted to know if its easy to implement outputting product titles along with its corresponding ASIN numbers (e.g. AB14324242 —> Apple iPhone).
Also, how easy or difficult would be to create an application like this?
hxxp://www.youtube.com/watch?v=mMBxbUAjUiE&list=UUruB4Z6HL5Ys6-AIkfYOgvA
Check this https://seegatesite.com/quickly-build-amazon-asin-grabber-with-simple-html-dom/
if you need to grab asin with title 🙂
hi,
with ASIN grabber all when ASIN get grabbed and when we put to CSV bulk import the products get imported but not all the variations. why it is so??
Is there any method to grab only parent ASINs because only variations are coming with the parent ASINs
Sory, i can’t do that 🙂
I Want Amazon Grabbing Tools for making Affiliate Webs Site.
If You Have Please Send Me Demo Link.
hello, sorry I haven’t used amazon in a while … so the script wasn’t updated.