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

Get Amazon Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.