开发者

Searching Amazon only returns 10 items

I am trying to get information on books from Amazon and feed that information. to my own web app. The problem is it only returned 10 results. How can I get the results after the开发者_运维技巧 first 10?


I assume you are using the ItemSearch operation from the Amazon Product Advertising API.

Your request should look like:

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]

This should return a response that looks like:

<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 results are paginated; the above request will return items 1 to 10 (corresponding to page 1). To get additional results, you need to request a different page of results. With Amazon ItemSearch operation, you do so by specifying the itemPage parameter.

Here is the sudo code that would fetch all the books by or about "Edward Tufte" available on Amazon (up to 400 pages of results):

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

Reference: [1] ItemSearch Amazon Product Documentation (Available at http://docs.amazonwebservices.com/AWSECommerceService/2010-11-01/DG/ItemSearch.html)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜