O'Reilly logo

Amazon Hacks by Paul Bausch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Add an Amazon Box to Your Site

Add a quick list of products to your site based on a category or keyword.

If you run a weblog, you probably have a nice, long sidebar filled with links to your favorite sites. You could turn some of this web real estate into a money-maker with associate links. But who has time to find the top products in a given category, copy the URLs to the product detail pages, and place them all in order on your site? That’s what an Amazon Box is for.

What’s an Amazon Box? It’s a simple HTML table that contains a list of products and that links to Amazon with your associate tag. You can use a Perl script by Rael Dornfest called Amazox to generate the box, making your life easier.

Amazox is run on-the-fly from the command line with the variables needed, so it’s easy to quickly create several boxes with different configurations if you have more than one page you’d like to add a box to.

The Code

This Perl script queries Amazon based on command-line arguments you supply. It requires two standard Perl modules: XML::Simple (http://search.cpan.org/author/GRANTM/) and LWP::UserAgent (http://search.cpan.org/author/GAAS/). Many Perl installations have these modules already installed, or you can find them on CPAN, the Comprehensive Perl Archive Network (http://www.cpan.org/).

Be sure to include your associate tag and developer token in the right spots. You can configure which Amazon catalog to search by changing the $product_line variable.

#!/usr/bin/perl -w # amazon_box.pl ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required