3

我正在尝试从亚马逊获取有关书籍的信息并提供这些信息。到我自己的网络应用程序。问题是它只返回了 10 个结果。如何获得前 10 名之后的结果?

4

1 回答 1

3

我假设您正在使用来自亚马逊产品广告 API 的 ItemSearch 操作。

您的请求应如下所示:

http://ecs.amazonaws.com/onca/xml?
Service=AWSECommerceService&
AWSAccessKeyId=[AWS Access Key ID]&
Operation=ItemSearch&
Keywords=Edward%20Tufte&
SearchIndex=Books
&Timestamp=[YYYY-MM-DDThh:mm:ssZ]
&Signature=[Request Signature]

这应该返回如下所示的响应:

<TotalResults>132</TotalResults>
<TotalPages>14</TotalPages>
<Item>
  <ASIN>...</ASIN>
  <DetailPageURL>...</DetailPageURL>
  <ItemAttributes>...</ItemAttributes>
</Item>
<Item>
  <ASIN>...</ASIN>
  <DetailPageURL>...</DetailPageURL>
  <ItemAttributes>...</ItemAttributes>
</Item>
<Item>
  <ASIN>...</ASIN>
  <DetailPageURL>...</DetailPageURL>
  <ItemAttributes>...</ItemAttributes>
</Item>
...

ItemSearch 结果是分页的;上述请求将返回项目 1 到 10(对应于第 1 页)。要获得更多结果,您需要请求不同的结果页面。对于 Amazon ItemSearch 操作,您可以通过指定 itemPage 参数来执行此操作。

这是 sudo 代码,它将获取亚马逊上可用的“Edward Tufte”或关于“Edward Tufte”的所有书籍(最多 400 页结果):

keywords="Edward Tufte"

# itemSearch will create the Amazon Product Advertising request
response=itemSearch(Keywords=keywords, SearchIndex="Books")
# Do whatever you want with the response for the first page
...

# getTotalPagesFromResponse will parse the XML response and return the totalPages
# (14 in the above example). 
totalPages = getTotalPagesFromResponse(response)
If totalPages > 1
  # Note that you cannot go beyond 400 pages (see [1])
  # Or you can limit yourself to a smaller number of pages
  totalPages=min(400,totalPages)

  page=2
  while page < totalPages
    response=itemSearch(Keywords=keywords, SearchIndex="Books", ItemPage=page)
    # Do whatever you want with the response
    ...
    page=page+1

参考:[1] ItemSearch Amazon 产品文档(可在http://docs.amazonwebservices.com/AWSECommerceService/2010-11-01/DG/ItemSearch.html 获得

于 2011-04-22T23:15:44.547 回答