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

Program XML/HTTP with VBScript

Accessing Amazon within Windows is a job for VBScript.

VBScript is a common scripting language for the Windows platform. It’s very similar to Visual Basic, and in fact this hack is modified from the example VBA application included with the Amazon developer’s kit. With a few slight modifications, this code could be used in a Word macro, a Visual Basic program, or an ASP web page. In this case, it’s written for Windows Scripting Host, and will run just like any other program.

What You Need

This example requires a Windows machine and the Microsoft XML Parser. If Internet Explorer 4.0 or higher is installed on your machine, the parser is already there.

The Code

Create a text file called amazon_price.vbs with the following code:

' amazon_price.vbs
' This VBScript prompts for an ASIN, and returns the price.
' Usage: double-click amazon_price.vbs, enter ASIN.

Sub AmazonQuery(ASIN_In)
  Dim SelectedText
  Dim MSXML
  Dim XMLURL
  Dim Loaded
    
  ' Make sure that some text is selected
  If ((Len(ASIN_In) = 0) Or (ASIN_In < " ")) Then
    WScript.Echo "Please enter an ASIN."
    Exit Sub
  End If
  
  ' Set Associate ID and Developer Token
  AffiliateTag = "insert associate tag"
  DeveloperToken = "insert developer token" ' Create an instance of the MSXML Parser Set MSXML = CreateObject("MSXML.DOMDocument") ' Set MSXML Options MSXML.Async = False MSXML.preserveWhiteSpace = False MSXML.validateOnParse = True MSXML.resolveExternals = False ' Form the request URL XMLURL = "http://xml.amazon.com/onca/xml3" ...

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