Section 19.2.  Amazon.com

Prev don't be afraid of buying books Next

19.2. Amazon.com

Amazon's Web service has an interesting business model. The service is free to use; it earns its money by increasing Amazon's sales. It is essentially a search service for Amazon's product line, but because the line in many areas is comprehensive, the service has research value as well: "How many books did Paul Prescod write? Did he ever record a DVD?"

19.2.1 Amazon Associates

Amazon has long had a model whereby "associates" can earn money by directing book buyers to the Amazon site. Amazon's Web service allows these vendors to integrate more tightly with Amazon's underlying databases.

Some even set up their own virtual store-fronts, selling books as if they were full-service retailers but allowing Amazon to do the actual fulfillment and billing. Entrepreneurial developers have created software that allows anyone to build a virtual storefront on top of the Amazon Web service in hours.

One innovative associate allows people to choose things from Amazon and then purchase them using currencies that Amazon does not support. The associate does the appropriate currency trading for you behind the scenes.

Everyone benefits from the Web service. The associates make more money by selling more products. The Web service gives them very accurate and timely information. When Amazon changes a price, they know quickly. Amazon makes a profit on most books it sells, so it benefits from giving the associates the tools they need to build their storefronts and sell books.

19.2.2 Why not HTML?

From the earliest days of the Amazon associates program, Amazon supplied HTML graphics and search boxes for associates to include on their Web pages. The links created by that HTML markup caused HTML pages to be displayed. That was o.k. for end users who wanted to buy books, but it was a nuisance for programmers who needed to integrate Amazon search results into complex Web pages or other applications.

In a nutshell: Amazon delivered renditions when the programmers needed abstractions!

Amazon's browser style is pretty elaborate, as you can see from the search results page in Figure 19-1. It shows that the most popular book about the keyword "genome" is called "Genome" and is by "Matt Ridley". It costs $11.20 at Amazon.

Figure 19-1. Amazon.com search results in a Web browser




It follows from the elaborate formatting that the corresponding HTML source is pretty elaborate as well, as you can see in Example 19-1. A programmer looking for the facts about the top search result has to ignore things in the HTML pages that are helpful to people but irrelevant to computers, such as fonts, tabular layouts, line breaks, and so forth.

Example 19-1. Partial HTML source of Figure 19-1
 <table border=0 cellpadding=3 width=100%> <tr valign=top> <td> <font size=-1><b>1.</b></font></td> <td align=center width=60> <font face=verdana,arial,helvetica size=-1> <a href=/exec/.../sr=2-1/ref=sr_2_1/103-5013077-5501429> <img src="/books/2/559/1/html/2/http://...PIt.arrow,TopLeft,-1,-17_SCTHUMBZZZ_.jpg"      width=42 height=66 align=left border=0></a> </font> </td> <td width=100% valign=top> <font face=verdana,arial,helvetica size=-1> <a href=/exec/.../sr=2-1/ref=sr_2_1/103-5013077-5501429> <b>Genome</b></a> -- by Matt Ridley (Author); Paperback <br> <span class=small> <a href=/exec/.../ref=sr_2_1/103-5013077-5501429> Buy new</a></span>: <b class=price>$11.20</b> -- <a href=http://.../all/ref=sr_pb_a/103-5013077-5501429> Used & new from</a>: <b class=price>$3.95</b> &nbsp; </font> </b> 

A program that analyzes a rendition to find abstract data is said to be screen scraping. Such programs are difficult to write because there is no guaranteed pattern of formatting markup. Worse yet, the program might break any time that Amazon decides to change the layout of the search results.

19.2.3 The Amazon Web service

The Amazon Web service eliminates the need for screen scraping by returning abstract XML documents. That makes it easy for programs to find the desired information elements.

Using the Web service, it is possible to construct queries similar to those that Amazon's user interface allows: search by author, search by ISBN, search by keyword, and so forth.

Consider Example 19-2, which shows the Web service query for books about "genome". You can actually type this query in a browser's address pane and see a rendition of the XML document that the service would return to a program.[3]

[3] Well, you once could have. As we went to press, Amazon changed its Web service interface and now requires a "developer's token" in its queries.

Example 19-2. Web service query (split into two lines to fit page width of this book)
 http://rcm.amazon.com/e/cm?t=encyclozine&l=st1 &search=genome&mode=books&pk102&o=1&f=xml 

If you ask the browser to "View Source", you will see the XML source of the search result, as shown in Example 19-3.[4]

[4] Note that in reality the content of tagged_url has no white space. It was broken into three lines in order to fit this book's page width.

Example 19-3. Partial XML source of Example 19-2 search result
 <?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <keyword>genome</keyword> <product_group>Books</product_group>   <product>     <ranking>1</ranking>     <title>Genome</title>     <asin>0060932902</asin>     <author>Ridley, Matt</author>     <image>       http://images.amazon.com/images/P/0060932902.01.MZZZZZZZ.jpg     </image>     <small_image>       http://images.amazon.com/images/P/0060932902.01.TZZZZZZZ.jpg     </small_image>     <our_price>$11.20</our_price>     <list_price>$14.00</list_price>     <release_date>20001003</release_date>     <binding>Paperback</binding>     <availability> </availability>     <tagged_url>http://www.amazon.com:80/exec/obidos/redirect?       tag=encyclozine&amp;creative=9441&amp;camp=1793       &amp;link_code=xml&amp;path=ASIN/0060932902</tagged_url>   </product>   -- more products here -- </catalog> 

As you can see, Example 19-3 yields much of the same information as Example 19-1. The top-ranked book about the keyword "genome" is called "Genome" and is by "Matt Ridley". It costs $11.20 at Amazon, which is a few dollars cheaper than its $14.00 list price. But unlike the HTML, this XML is about as straightforward as you could hope for.

This Web service is SOAPless; Amazon offers a SOAPy version as well, which returns a substantially more complex document. We'll look at a SOAP-based service next, but instead of Amazon we'll use the equally famous Google.

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net