我需要能够使用亚马逊API获取产品的所有优惠清单。这是我发送的请求:
http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&Operation=ItemLookup&SubscriptionId=&AssociateTag=&Version=2011-08-01&ItemId=B007IJQDQQ&IdType=ASIN&ResponseGroup=Offers&Condition=All&MerchantId=All
这将返回以下优惠:
<Offers>
<TotalOffers>1</TotalOffers>
<TotalOfferPages>1</TotalOfferPages>
<MoreOffersUrl>
http://www.amazon.com/gp/offer-listing/B007IJQDQQ%3FSubscriptionId%3DAKIAJTZ6VROOTPJAPPWQ%26tag%3Damazoautom-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB007IJQDQQ
</MoreOffersUrl>
<Offer>
<OfferAttributes>
<Condition>New</Condition>
</OfferAttributes>
<OfferListing>
<OfferListingId>
TR5sygI0VR7cwy3Hg0DBHwgCWFnkqXLyCR70jjMhy1h8gWlEisKYt5cqDbS2Fu1SEqDtfBILdxYDziJdFzfsqMpPJkBqcYV3DFovHx1nXWRy9wHS6CFZXknBvsCo1bxYS%2BsxAeYrZHrS6g6aakEJQA%3D%3D
</OfferListingId>
<Price>
<Amount>375</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$3.75</FormattedPrice>
</Price>
<AmountSaved>
<PercentageSaved>56</PercentageSaved>
<Availability>Usually ships in 1-2 business days</Availability>
<AvailabilityAttributes>
<IsEligibleForSuperSaverShipping>0</IsEligibleForSuperSaverShipping>
</OfferListing>
</Offer>
</Offers>
正如您所看到的那样,它只会返回1个优惠,即使它表示有3个新优惠。有没有人知道如何获得所有优惠而不仅仅是最低价?商家ID ='ALL'不执行此操作,也不执行任何其他响应组,例如offerFull,offerSummary或offer。
答案 0 :(得分:13)
在进行一些研究之后,这在API中是不可能的,但是您可以解析标准页面的HTML以获取详细信息:
1)使用http://simplehtmldom.sourceforge.net/解析HTML(如果你不使用php,你需要找到类似的东西)
2)CURL(确保您设置标题或亚马逊会出错)http://www.amazon.com/gp/offer-listing/B007IJQDQQ/?condition=new和http://www.amazon.com/gp/offer-listing/B007IJQDQQ/?condition=used
3)处理页数总数(找到#new span.numberreturned)并除以15以计算出页数。
4)你需要解析每个页面,URL就像一些:
例如第2页 http://www.amazon.com/gp/offer-listing/B005IMB5SG/?condition=used&startIndex=15
例如第3页 http://www.amazon.com/gp/offer-listing/B005IMB5SG/?condition=used&startIndex=30
希望这是足够的信息让你开始,抱歉我无法访问我刚才写的工作脚本。
答案 1 :(得分:0)
Product API scratch pad返回&#34;所有优惠&#34;您可以通过HTTP手动获取并解析的链接,以提供包含所需信息的DOM节点列表。
它类似于几年前提到的http://www.amazon.com/gp/offer-listing/B007IJQDQQ/?condition=used
链接@dciso,但其中包含的API信息可以帮助您更好地遵循亚马逊规则。
<ItemLookupResponse>
<Items>
<Item>
<ASIN>B00I8BICB2</ASIN>
<ParentASIN>B077PSDB4X</ParentASIN>
<DetailPageURL>https://www.amazon.com/Sony-Mirrorless-Digitial-3-0-Inch-16-50mm/dp/B00I8BICB2?psc=1&SubscriptionId_____tag=_____&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B00I8BICB2</DetailPageURL>
<ItemLinks>
...
<ItemLink>
<Description>All Offers</Description>
<URL>https://www.amazon.com/gp/offer-listing/B00I8BICB2?SubscriptionId=______&tag=_____&linkCode=xm2&camp=2025&creative=386001&creativeASIN=B00I8BICB2</URL>
</ItemLink>
</ItemLinks>