O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  


 
Buy the book!
Amazon Hacks
By Paul Bausch
August 2003
More Info

HACK
#35
Publish Your Amazon Reviews on Your Site
With a little screen scraping, you can gather all the reviews you've posted to Amazon and publish them on your own web site
The Code
[Discuss (0) | Link to this hack]

The Code

The following ASP script requires your Amazon ID. Create a file called my_reviews.asp and enter the following code:

<% Const AmazonID = "insert Amazon ID" %>
<html>
<head>
    <title>My Amazon Reviews</title>
</head>

<body>
<%
strURL = "http://www.amazon.com/exec/obidos/tg/cm/member-reviews/-/" & _
          AmazonID & "/t/"
Set xmlhttp = Server.CreateObject("Msxml2.SERVERXMLHTTP")
xmlhttp.Open "GET", strURL, false
xmlhttp.Send(Now)
strContent = xmlhttp.responseText
Set xmlhttp = Nothing

Set objRegExpr = New regexp
objRegExpr.Pattern = "<a [^>].*detail/-/(.*?)/[^>].*><b>(.*?)</b>[\s\S]*?(\&return;
d) out of 5 stars[\s\S]*?<b>(.*?)</b> \n(.*?)\n<br>\n(.*?)\n<br><br>"
objRegExpr.Global = True
objRegExpr.IgnoreCase = True
Set objMatches = objRegExpr.Execute(strContent)
If objMatches.Count = 0 Then
    response.write "No reviews found."
Else
    For Each objMatch In objMatches
        strASIN = objMatch.SubMatches(0)
        strTitle = objMatch.SubMatches(1)
        strRating = objMatch.SubMatches(2)
        strReviewTitle = objMatch.SubMatches(3)
        strReviewDate = objMatch.SubMatches(4)
        strReviewText = objMatch.SubMatches(5)
        response.write "<u>" & strTitle & "</u> - "
        response.write "ASIN: " & strASIN & "<br>"
        response.write "(" & strRating & " stars.) "
        response.write "<b>" & strReviewTitle & "</b>, " 
        response.write strReviewDate & "<br>"
        response.write "<blockquote>" & strReviewText & "</blockquote>"
        response.write "<br><br>"
        response.flush
    Next
End If
Set objMatches = Nothing
Set objRegExpr = Nothing
%>
</body>
</html>

This code requests the review page from Amazon and finds matches in the HTML for the relevant data. It breaks the review down into its parts (ASIN, title, rating, review title, date, and review text) and formats it for the page.


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.