以编程方式访问亚马逊心愿单?

发布于 2024-10-10 00:07:00 字数 102 浏览 0 评论 0原文

亚马逊最近更改了他们的 API,现在似乎无法使用这些 API 以编程方式访问我在亚马逊上的愿望清单。除了屏幕抓取之外,有人知道还有什么方法吗?也许是一些第三方服务(我不介意仅使用公共数据)?

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小耗子 2024-10-17 00:07:00

对于屏幕抓取,紧凑的布局样式可能会有所帮助:http://bililite.com/blog/2010/10/31/hacking-my-way-to-an-amazon-wishlist-widget/

更新

我自己在谷歌电子表格中进行了一些黑客攻击,并设法使 2 个基本实现正常工作。

使用 Google Apps 脚本

在单元格 A1 中输入您的愿望清单 ID。将以下内容复制并粘贴到 google apps 脚本中(工具 > 脚本 > 脚本编辑器),然后运行 ​​getWishlist 函数:

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);
}

注意,我在正则表达式与标题/价格匹配时遇到了一些问题。不知道为什么,但显示了基本思想。

使用 Google 电子表格功能

在单元格 A1 中输入您的心愿单 ID。

在 A2 中键入以下函数。它将使用您的愿望清单中每个项目的 id 字符串填充该单元格及其下方的所有内容:

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

在 B2 中键入以下函数,这将从 id 字符串中提取 asin:

=right(A2, 10)

在 B3 中键入以下函数,这将获取报价列表对于 B2 中的 asin 并显示标题:

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

在 B4 中键入以下函数,这将获取 B2 中的 asin 的报价列表并显示所有价格:

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

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']"))
老旧海报 2024-10-17 00:07:00

一个叫 Justin Scarpetti 的人创建了一个非常简洁的“api”,它可以抓取你的愿望清单并以 json 格式返回数据。

这是一个用于检索亚马逊愿望清单数据的小 API。没有
官方 API,亚马逊几年前关闭了它。唯一的办法
围绕着...屏幕抓取。

Amazon Wish Lister 使用 phpQuery(服务器端 CSS3 选择器驱动的 DOM)
基于 jQuery 的 API)抓取亚马逊的愿望清单页面并导出到
JSON、XML 或 PHP 数组对象。

如果您想自行展示您的愿望清单,那么这是完美的选择
网站。

来源:亚马逊愿望清单

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文