Programmatic access to Amazon Wishlist?

19,258

Solution 1

For screen scraping, the compact layout style might be helpful: http://bililite.com/blog/2010/10/31/hacking-my-way-to-an-amazon-wishlist-widget/

Update

I did some hacking of my own in google spreadsheets and managed to get 2 basic implementations working.

Using Google Apps Scripts:

Type your wishlist ID into cell A1. Copy and paste the following into a google apps script (Tools > Scripts > Scripts Editor), and run the getWishlist function:

function getWishlist(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  var wishlistId = sheet.getRange('a1').getValue(); 
  var response = UrlFetchApp.fetch("http://www.amazon.co.uk/registry/wishlist/" + wishlistId + "?layout=compact").getContentText();
  var asinRegex = /name="item.([\d]+)\.(?:[A-Z0-9]+).([A-Z0-9]+).*/g
  while (match = asinRegex.exec(response)) {
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
    var rowIndex = Number(match[1])+2;
    var asin = match[2];
    setRow(sheet, rowIndex, asin);
    var offers = UrlFetchApp.fetch("http://www.amazon.co.uk/gp/offer-listing/" + asin).getContentText();    
    setRow(sheet, rowIndex, asin, 
           getFirstMatch(/class="producttitle">(.+)</g, offers),
           getFirstMatch(/class="price">(.+)</g, offers));
  }  
  Browser.msgBox("Finished");
}

function getFirstMatch(regex, text) {
  var match = regex.exec(text);
  return (match == null) ? "Unknown" : match[1];
}

function setRow(sheet, index, a, b, c) {
  sheet.getRange('a' + index).setValue(a);
  sheet.getRange('b' + index).setValue(b);
  sheet.getRange('c' + index).setValue(c);
}

​ ​ NB, I'm having some probs with regex matching the title / price. Not sure why, but shows the basic idea.

Using Google Spreadsheet Functions

Type your wishlist ID into cell A1.

Type the following function into A2. It will populate the cell and all below it with the id strings for each item in your wishlist:

=importXML("http://www.amazon.co.uk/registry/wishlist/"&A1&"?layout=compact", "//*[starts-with(@name, 'item.')]/@name")

Type the following function into B2, which will extract the asin from the id string:

=right(A2, 10)

Type the following function into B3, which will fetch the offer listing for the asin in B2 and display the title:

=importXML("http://www.amazon.co.uk/gp/offer-listing/"&B2, "//h1")

Type the following function into B4, which will fetch the offer listing for the asin in B2 and display all the prices:

=concatenate(importXML("http://www.amazon.co.uk/gp/offer-listing/"&B2, "//span[@class='price']"))

Solution 2

A guy called Justin Scarpetti has created a really neat "api" which scrapes your wishlist and returns the data in json format.

This is a little API to retrieve Amazon Wish List data. There is no official API, as Amazon shut it down a couple years ago. The only way around that... screen scraping.

Amazon Wish Lister uses phpQuery (server-side CSS3 selector driven DOM API based on jQuery) to scrape Amazon's Wish List page and exports to JSON, XML, or PHP Array Object.

Perfect if you want to host display your wish list on your own website.

Source: Amazon Wish Lister

Share:
19,258
StasM
Author by

StasM

Programmer (Unix, Windows, C, C++, PHP, Pyhon, Java, etc.)

Updated on August 02, 2022

Comments

  • StasM
    StasM almost 2 years

    Amazon recently changed their APIs which and it seems there's no way now to access my WishList on Amazon programmatically using these APIs. Anybody knows any way to do it besides screen-scraping? Maybe some third-party service (I don't mind working with only public data)?

  • Larry G. Wapnitsky
    Larry G. Wapnitsky about 10 years
    just tried this, substituting amazon.com for amazon.co.uk. getting xpath query errors. any ideas?
  • robd
    robd about 10 years
    @LarryG.Wapnitsky This code is based on amazon as it was 3 years ago, so the HTML has probably changed. Can you share more details on the error you're seeing, or share your Google spreadsheet and I'll take a look.
  • Vijay Sharma
    Vijay Sharma over 6 years
    Hey Andy, Can I use this at the mobile end? if yes then please let me know the way.
  • Andy Davies
    Andy Davies over 6 years
    hi @Kumar sorry but I can't provide any advice on integrating this with a mobile backend. But with the output being JSON you should be able to use this in mobile app development without too much trouble.