Free Amazon Asin Grabber Plugin and Tutorial

Free Amazon Asin Grabber as WordPress Plugin

Previously I made an article about Quickly Build Amazon ASIN Grabber with Simple Html DOM , For easy to use, I try create this script into wordpress plugin. With this plugin you can have your own 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 🙂 )

  • For create wordpress plugin, we need to write Standard Plugin Information header. This header lets WordPress recognize that your Plugin exists, add it to the Plugin management screen so it can be activated, load it, and run its functions; without the header, your Plugin will never be activated and will never run ( Read more how to create wordpress plugin here wordpress.org ). Create new php file, give name as asin-grabber.php

/*
Plugin Name: Amazon Asin Grabber
Plugin URI: http://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: http://seegatesite.com/
*/

  • Create add_action to locate your plugin menu

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
<?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).

action="<?php echo asin_back();?>"

Create function asin_back() in the above of asin_grabber_func().


function asin_back(){
return admin_url("options-general.php?page=asin-grab");
}

The function is , after we submit the form, we call asin_back() function to return.

  • Create function to grab asin , give name as graburl()

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="http://seegatesite.com" target="_blank">Seegatesite</a>';
return $retval;
}

Voila, Your asin grabber plugin has been created 🙂

If you need to download example amazon asin grabber , click link below 
[Locker] The locker [id=0] doesn't exist or the default lockers were deleted.
. or download here http://wordpress.org/plugins/amazon-asin-grabber/

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.

8 Comments

 Add your comment
  1. 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..

  2. whenever i enter url and click submit it gives me 404 error

  3. 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

  4. 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

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: