【背景】
折腾:
之后,接着需要去实现,通过AWS的BrowseNodeLookup:
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeLookup.html
去实现,类似于网页中的,Amazon的那30多个主的大类的产品的查询。
【解决过程】
1.其中,相关的Browse Node IDs参考:
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeIDs.html
2.通过代码:
private static void browseNodeLookupTest(SignedRequestHelper helper) { /* * Here is an ItemLookup example where the request is stored as a dictionary. */ IDictionary<string, string> reqDict = new Dictionary<string, String>(); reqDict["Service"] = "AWSECommerceService"; reqDict["Version"] = awsApiVersion; reqDict["Operation"] = "BrowseNodeLookup"; //http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeIDs.html //2619525011 -> Appliances reqDict["BrowseNodeId"] = "2619525011"; reqDict["ResponseGroup"] = "BrowseNodeInfo"; /* * The helper supports two forms of requests - dictionary form and query string form. */ String requestUrl; requestUrl = helper.Sign(reqDict); WebRequest request = HttpWebRequest.Create(requestUrl); WebResponse response = request.GetResponse(); XmlDocument doc = new XmlDocument(); doc.Load(response.GetResponseStream()); //for debug System.Console.WriteLine(doc.InnerXml); }
返回的xml是:
<BrowseNodeLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>05520d7a-33ac-4913-96a9-6185a833892e</RequestId> <Arguments> <Argument Name="Operation" Value="BrowseNodeLookup" /> <Argument Name="Service" Value="AWSECommerceService" /> <Argument Name="Signature" Value="SK3M+ywbdDp4nucUe5bdDZANf6UrY9z+4wUzIrGtQOY=" /> <Argument Name="AssociateTag" Value="xxx" /> <Argument Name="Version" Value="2011-08-02" /> <Argument Name="BrowseNodeId" Value="2619525011" /> <Argument Name="AWSAccessKeyId" Value="xxx" /> <Argument Name="Timestamp" Value="2013-06-13T12:18:04Z" /> <Argument Name="ResponseGroup" Value="BrowseNodeInfo" /> </Arguments> <RequestProcessingTime>0.010225</RequestProcessingTime> </OperationRequest> <BrowseNodes> <Request> <IsValid>True</IsValid> <BrowseNodeLookupRequest> <BrowseNodeId>2619525011</BrowseNodeId> <ResponseGroup>BrowseNodeInfo</ResponseGroup> </BrowseNodeLookupRequest> </Request> <BrowseNode> <BrowseNodeId>2619525011</BrowseNodeId> <Name>Appliances</Name> <Children> <BrowseNode> <BrowseNodeId>2619526011</BrowseNodeId> <Name>Categories</Name> <IsCategoryRoot>1</IsCategoryRoot> </BrowseNode> <BrowseNode> <BrowseNodeId>2645269011</BrowseNodeId> <Name>Featured Categories</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2645372011</BrowseNodeId> <Name>Self Service</Name> </BrowseNode> </Children> </BrowseNode> </BrowseNodes> </BrowseNodeLookupResponse>
很明显,没有出现,访问:
http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dappliances&field-keywords=
中所出现的,那几十个子分类,从:
Air Conditioners 到 Wine Cellars。
3.再去试试,其中的那个IsCategoryRoot为1的2619526011:
private static void browseNodeLookupTest(SignedRequestHelper helper) { /* * Here is an ItemLookup example where the request is stored as a dictionary. */ IDictionary<string, string> reqDict = new Dictionary<string, String>(); reqDict["Service"] = "AWSECommerceService"; reqDict["Version"] = awsApiVersion; reqDict["Operation"] = "BrowseNodeLookup"; //http://docs.aws.amazon.com/AWSECommerceService/latest/DG/BrowseNodeIDs.html //2619525011 -> Appliances //reqDict["BrowseNodeId"] = "2619525011"; //<BrowseNodeId>2619525011</BrowseNodeId> //<Name>Appliances</Name> //<Children> // <BrowseNode> // <BrowseNodeId>2619526011</BrowseNodeId> // <Name>Categories</Name> // <IsCategoryRoot>1</IsCategoryRoot> // </BrowseNode> reqDict["BrowseNodeId"] = "2619526011"; reqDict["ResponseGroup"] = "BrowseNodeInfo"; /* * The helper supports two forms of requests - dictionary form and query string form. */ String requestUrl; requestUrl = helper.Sign(reqDict); WebRequest request = HttpWebRequest.Create(requestUrl); WebResponse response = request.GetResponse(); XmlDocument doc = new XmlDocument(); doc.Load(response.GetResponseStream()); //for debug System.Console.WriteLine(doc.InnerXml); }
返回xml是:
<BrowseNodeLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>c1435dc8-a7a0-4167-92e9-80039bad49b6</RequestId> <Arguments> <Argument Name="Operation" Value="BrowseNodeLookup" /> <Argument Name="Service" Value="AWSECommerceService" /> <Argument Name="Signature" Value="J1WgQm1G0D/eAEf6U8ZQBsdptHx+XFjPcMBmuA9bvrM=" /> <Argument Name="AssociateTag" Value="xxx" /> <Argument Name="Version" Value="2011-08-02" /> <Argument Name="BrowseNodeId" Value="2619526011" /> <Argument Name="AWSAccessKeyId" Value="xxx" /> <Argument Name="Timestamp" Value="2013-06-13T12:39:29Z" /> <Argument Name="ResponseGroup" Value="BrowseNodeInfo" /> </Arguments> <RequestProcessingTime>0.002589</RequestProcessingTime> </OperationRequest> <BrowseNodes> <Request> <IsValid>True</IsValid> <BrowseNodeLookupRequest> <BrowseNodeId>2619526011</BrowseNodeId> <ResponseGroup>BrowseNodeInfo</ResponseGroup> </BrowseNodeLookupRequest> </Request> <BrowseNode> <BrowseNodeId>2619526011</BrowseNodeId> <Name>Categories</Name> <IsCategoryRoot>1</IsCategoryRoot> <Children> <BrowseNode> <BrowseNodeId>3737671</BrowseNodeId> <Name>Air Conditioners</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>267554011</BrowseNodeId> <Name>Air Purifiers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2632820011</BrowseNodeId> <Name>Appliance Services</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2242350011</BrowseNodeId> <Name>Appliance Warranties</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2686378011</BrowseNodeId> <Name>Beer Keg Refrigerators</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2686328011</BrowseNodeId> <Name>Beverage Refrigerators</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>495362</BrowseNodeId> <Name>Ceiling Fans & Accessories</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>678542011</BrowseNodeId> <Name>Compact Refrigerators</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741261</BrowseNodeId> <Name>Cooktops</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>267557011</BrowseNodeId> <Name>Dehumidifiers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741271</BrowseNodeId> <Name>Dishwashers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3737601</BrowseNodeId> <Name>Fans</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741331</BrowseNodeId> <Name>Freezers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>680343011</BrowseNodeId> <Name>Garbage Disposals</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>267555011</BrowseNodeId> <Name>Humidifiers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2399939011</BrowseNodeId> <Name>Ice Makers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>510240</BrowseNodeId> <Name>Irons, Steamers & Accessories</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>289935</BrowseNodeId> <Name>Microwave Ovens</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741181</BrowseNodeId> <Name>Parts & Accessories</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741441</BrowseNodeId> <Name>Range Hoods</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741411</BrowseNodeId> <Name>Ranges</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741361</BrowseNodeId> <Name>Refrigerators</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>289913</BrowseNodeId> <Name>Small Appliances</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>510182</BrowseNodeId> <Name>Space Heaters</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741451</BrowseNodeId> <Name>Trash Compactors</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>510106</BrowseNodeId> <Name>Vacuums & Floor Care</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741481</BrowseNodeId> <Name>Wall Ovens</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2399955011</BrowseNodeId> <Name>Warming Drawers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>2383576011</BrowseNodeId> <Name>Washers & Dryers</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3741521</BrowseNodeId> <Name>Wine Cellars</Name> </BrowseNode> </Children> <Ancestors> <BrowseNode> <BrowseNodeId>2619525011</BrowseNodeId> <Name>Appliances</Name> </BrowseNode> </Ancestors> </BrowseNode> </BrowseNodes> </BrowseNodeLookupResponse>
就是我们所需要的结果了:
所有的子分类的ID和名字,从ID为3737671的Air Conditioners,到ID为3741521的Wine Cellars
4.然后就接着再去试试,第一个子分类,ID为3737671的Air Conditioners,看看能否得到产品数据:
//<Children> // <BrowseNode> // <BrowseNodeId>3737671</BrowseNodeId> // <Name>Air Conditioners</Name> // </BrowseNode> reqDict["BrowseNodeId"] = "3737671"; reqDict["ResponseGroup"] = "BrowseNodeInfo";
返回xml是:
<BrowseNodeLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>54190300-c977-4b9b-8194-f91d6c2eef34</RequestId> <Arguments> <Argument Name="Operation" Value="BrowseNodeLookup" /> <Argument Name="Service" Value="AWSECommerceService" /> <Argument Name="Signature" Value="m00R00zTRW7zr9gitSEJg15jYEWo2nSWtBbSo0s1soc=" /> <Argument Name="AssociateTag" Value="xxx" /> <Argument Name="Version" Value="2011-08-02" /> <Argument Name="BrowseNodeId" Value="3737671" /> <Argument Name="AWSAccessKeyId" Value="xxx" /> <Argument Name="Timestamp" Value="2013-06-13T12:44:12Z" /> <Argument Name="ResponseGroup" Value="BrowseNodeInfo" /> </Arguments> <RequestProcessingTime>0.001778</RequestProcessingTime> </OperationRequest> <BrowseNodes> <Request> <IsValid>True</IsValid> <BrowseNodeLookupRequest> <BrowseNodeId>3737671</BrowseNodeId> <ResponseGroup>BrowseNodeInfo</ResponseGroup> </BrowseNodeLookupRequest> </Request> <BrowseNode> <BrowseNodeId>3737671</BrowseNodeId> <Name>Air Conditioners & Accessories</Name> <Children> <BrowseNode> <BrowseNodeId>3737761</BrowseNodeId> <Name>Energy Star Qualified</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3737741</BrowseNodeId> <Name>Multiroom</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>1193678</BrowseNodeId> <Name>Portable</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3737751</BrowseNodeId> <Name>Single-Room</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3737701</BrowseNodeId> <Name>Slider Casement</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3737711</BrowseNodeId> <Name>Wall</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3737721</BrowseNodeId> <Name>Window</Name> </BrowseNode> <BrowseNode> <BrowseNodeId>3737681</BrowseNodeId> <Name>Parts & Accessories</Name> </BrowseNode> </Children> <Ancestors> <BrowseNode> <BrowseNodeId>3206324011</BrowseNodeId> <Name>Heating, Cooling & Air Quality</Name> <Ancestors> <BrowseNode> <BrowseNodeId>1063498</BrowseNodeId> <Name>Categories</Name> <IsCategoryRoot>1</IsCategoryRoot> <Ancestors> <BrowseNode> <BrowseNodeId>1055398</BrowseNodeId> <Name>Home & Kitchen</Name> </BrowseNode> </Ancestors> </BrowseNode> </Ancestors> </BrowseNode> </Ancestors> </BrowseNode> </BrowseNodes> </BrowseNodeLookupResponse>
即,和网页中:
显示出来的效果一样的,
显示其子分类:
从第一个,ID为3737761的Energy Star Qualified,到最后一个,ID为3737681的Parts & Accessories
5.所以接着再去试试,第一个,ID为3737761的Energy Star Qualified的分类:
//<BrowseNode> // <BrowseNodeId>3737671</BrowseNodeId> // <Name>Air Conditioners & Accessories</Name> // <Children> // <BrowseNode> // <BrowseNodeId>3737761</BrowseNodeId> // <Name>Energy Star Qualified</Name> // </BrowseNode> reqDict["BrowseNodeId"] = "3737761";
返回xml是:
<BrowseNodeLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>6cbae38c-a4d5-43cf-9d7d-59c5c73e86f4</RequestId> <Arguments> <Argument Name="Operation" Value="BrowseNodeLookup" /> <Argument Name="Service" Value="AWSECommerceService" /> <Argument Name="Signature" Value="aKg6+9WC65aO1N02j4BVzelX2iht6LSk5/9NHWrZdfU=" /> <Argument Name="AssociateTag" Value="xxx" /> <Argument Name="Version" Value="2011-08-02" /> <Argument Name="BrowseNodeId" Value="3737761" /> <Argument Name="AWSAccessKeyId" Value="xxx" /> <Argument Name="Timestamp" Value="2013-06-13T12:47:59Z" /> <Argument Name="ResponseGroup" Value="BrowseNodeInfo" /> </Arguments> <RequestProcessingTime>0.002083</RequestProcessingTime> </OperationRequest> <BrowseNodes> <Request> <IsValid>True</IsValid> <BrowseNodeLookupRequest> <BrowseNodeId>3737761</BrowseNodeId> <ResponseGroup>BrowseNodeInfo</ResponseGroup> </BrowseNodeLookupRequest> </Request> <BrowseNode> <BrowseNodeId>3737761</BrowseNodeId> <Name>Energy Star Qualified</Name> <Ancestors> <BrowseNode> <BrowseNodeId>3737671</BrowseNodeId> <Name>Air Conditioners & Accessories</Name> <Ancestors> <BrowseNode> <BrowseNodeId>3206324011</BrowseNodeId> <Name>Heating, Cooling & Air Quality</Name> <Ancestors> <BrowseNode> <BrowseNodeId>1063498</BrowseNodeId> <Name>Categories</Name> <IsCategoryRoot>1</IsCategoryRoot> <Ancestors> <BrowseNode> <BrowseNodeId>1055398</BrowseNodeId> <Name>Home & Kitchen</Name> </BrowseNode> </Ancestors> </BrowseNode> </Ancestors> </BrowseNode> </Ancestors> </BrowseNode> </Ancestors> </BrowseNode> </BrowseNodes> </BrowseNodeLookupResponse>
就只有最后一级的浏览节点了。
但是此处希望是,网页浏览:
一样,可以获得该最叶子分类下,所有的产品的数据。
6.所以就想办法,在如何获得了某个browserNode前提下,查找旗下所有的产品。
然后看了看:
的解释,觉得貌似是需要再去通过
去找该分类下面的产品。
7.然后用了下面代码:
private static void itemSearchTest(SignedRequestHelper helper) { /* * Here is an ItemLookup example where the request is stored as a dictionary. */ IDictionary<string, string> reqDict = new Dictionary<string, String>(); reqDict["Service"] = "AWSECommerceService"; reqDict["Version"] = awsApiVersion; reqDict["Operation"] = "ItemSearch"; reqDict["SearchIndex"] = "None"; reqDict["ResponseGroup"] = "ItemIds"; //Home & Kitchen -> Heating, Cooling & Air Quality -> Air Conditioners & Accessories -> Energy Star Qualified reqDict["BrowseNodeId"] = "3737761"; String requestUrl = helper.Sign(reqDict); WebRequest request = HttpWebRequest.Create(requestUrl); WebResponse response = request.GetResponse(); XmlDocument doc = new XmlDocument(); doc.Load(response.GetResponseStream()); //for debug System.Console.WriteLine(doc.InnerXml); }
结果出错了:
<?xml version="1.0"?> <ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>1e73a18a-cf53-4fdc-9891-6f7573e59aab</RequestId> <Arguments> <Argument Name="Operation" Value="ItemSearch"/> <Argument Name="Service" Value="AWSECommerceService"/> <Argument Name="Signature" Value="dq2dDHLFmvxf/T1LfuvpNXJO32+4TsCoCdTIe3OhjeQ="/> <Argument Name="AssociateTag" Value="xxx"/> <Argument Name="Version" Value="2011-08-02"/> <Argument Name="BrowseNodeId" Value="3737761"/> <Argument Name="AWSAccessKeyId" Value="xxx"/> <Argument Name="Timestamp" Value="2013-06-13T13:03:43Z"/> <Argument Name="ResponseGroup" Value="ItemIds"/> <Argument Name="SearchIndex" Value="None"/> </Arguments> <RequestProcessingTime>0.0034130000000000</RequestProcessingTime> </OperationRequest> <Items> <Request> <IsValid>False</IsValid> <ItemSearchRequest> <ResponseGroup>ItemIds</ResponseGroup> <SearchIndex>None</SearchIndex> </ItemSearchRequest> <Errors> <Error> <Code>AWS.InvalidEnumeratedParameter</Code> <Message>The value you specified for SearchIndex is invalid. Valid values include [\n\t\t\t\t'All','Apparel','Appliances','ArtsAndCrafts','Automotive','Baby','Beauty','Blended','Books','Classical','Collectibles','DVD','DigitalMusic','Electronics','GiftCards','GourmetFood','Grocery','HealthPersonalCare','HomeGarden','Industrial','Jewelry','KindleStore','Kitchen','LawnAndGarden','Marketplace','MP3Downloads','Magazines',,'Miscellaneous','Music','MusicTracks','MusicalInstruments','MobileApps','OfficeProducts','OutdoorLiving','PCHardware','PetSupplies','Photo','Shoes','Software','SportingGoods','Tools','Toys','UnboxVideo','VHS','Video','VideoGames','Watches','Wireless','WirelessAccessories'\n\t\t\t\t].</Message> </Error> <Error> <Code>AWS.MinimumParameterRequirement</Code> <Message>Your request should have atleast 1 of the following parameters: 'Keywords','Title','Power','BrowseNode','Artist','Author','Actor','Director','AudienceRating','Manufacturer','MusicLabel','Composer','Publisher','Brand','Conductor','Orchestra','TextStream','Cuisine','City','Neighborhood'.</Message> </Error> </Errors> </Request> </Items> </ItemSearchResponse>
8.所以,再去添加对应的SearchIndex:
//reqDict["SearchIndex"] = "None"; reqDict["SearchIndex"] = "HomeGarden"; reqDict["ResponseGroup"] = "ItemIds"; //Home & Kitchen -> Heating, Cooling & Air Quality -> Air Conditioners & Accessories -> Energy Star Qualified reqDict["BrowseNodeId"] = "3737761";
结果竟然还报错:
<?xml version="1.0"?> <ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>277f477a-0eab-4efe-8245-430913085f16</RequestId> <Arguments> <Argument Name="Operation" Value="ItemSearch"/> <Argument Name="Service" Value="AWSECommerceService"/> <Argument Name="Signature" Value="IjY+aLZhigv0OJzJM5DyxY4E3NPtMHUuqUgLwKT8vIw="/> <Argument Name="AssociateTag" Value="xxx"/> <Argument Name="Version" Value="2011-08-02"/> <Argument Name="BrowseNodeId" Value="3737761"/> <Argument Name="AWSAccessKeyId" Value="xxx"/> <Argument Name="Timestamp" Value="2013-06-13T13:07:07Z"/> <Argument Name="ResponseGroup" Value="ItemIds"/> <Argument Name="SearchIndex" Value="HomeGarden"/> </Arguments> <RequestProcessingTime>0.0024860000000000</RequestProcessingTime> </OperationRequest> <Items> <Request> <IsValid>False</IsValid> <ItemSearchRequest> <ResponseGroup>ItemIds</ResponseGroup> <SearchIndex>HomeGarden</SearchIndex> </ItemSearchRequest> <Errors> <Error> <Code>AWS.MinimumParameterRequirement</Code> <Message>Your request should have atleast 1 of the following parameters: 'Keywords','Title','Power','BrowseNode','Artist','Author','Actor','Director','AudienceRating','Manufacturer','MusicLabel','Composer','Publisher','Brand','Conductor','Orchestra','TextStream','Cuisine','City','Neighborhood'.</Message> </Error> </Errors> </Request> </Items> </ItemSearchResponse>
9.然后才发现,原来自己用的是BrowseNodeId而不是人家要的BrowseNode
所以再改为:
//reqDict["SearchIndex"] = "None"; reqDict["SearchIndex"] = "HomeGarden"; reqDict["ResponseGroup"] = "ItemIds"; //Home & Kitchen -> Heating, Cooling & Air Quality -> Air Conditioners & Accessories -> Energy Star Qualified //reqDict["BrowseNodeId"] = "3737761"; reqDict["BrowseNode"] = "3737761";
终于可以得到所要的产品数据了:
<?xml version="1.0"?> <ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>d056191a-13d5-422a-a4fe-fc2b50d7c56d</RequestId> <Arguments> <Argument Name="Operation" Value="ItemSearch"/> <Argument Name="Service" Value="AWSECommerceService"/> <Argument Name="Signature" Value="azUu3ODipJ9cIeYWwDIsTOeLN9Ozqidy0+kJbPpmwUI="/> <Argument Name="AssociateTag" Value="xxx"/> <Argument Name="BrowseNode" Value="3737761"/> <Argument Name="Version" Value="2011-08-02"/> <Argument Name="AWSAccessKeyId" Value="xxx"/> <Argument Name="Timestamp" Value="2013-06-13T13:10:06Z"/> <Argument Name="ResponseGroup" Value="ItemIds"/> <Argument Name="SearchIndex" Value="HomeGarden"/> </Arguments> <RequestProcessingTime>0.2485140000000000</RequestProcessingTime> </OperationRequest> <Items> <Request> <IsValid>True</IsValid> <ItemSearchRequest> <BrowseNode>3737761</BrowseNode> <ResponseGroup>ItemIds</ResponseGroup> <SearchIndex>HomeGarden</SearchIndex> </ItemSearchRequest> </Request> <TotalResults>51</TotalResults> <TotalPages>6</TotalPages> <MoreSearchResultsUrl>http://www.amazon.com/gp/redirect.html?camp=2025&creative=386001&location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fsearch%3Fnode%3D3737761%26url%3Dsearch-alias%253Dgarden&linkCode=xm2&tag=xxx&SubscriptionId=xxx</MoreSearchResultsUrl> <Item> <ASIN>B002QK9YZ4</ASIN> </Item> <Item> <ASIN>B00008WAMK</ASIN> </Item> <Item> <ASIN>B007XH7HS6</ASIN> </Item> <Item> <ASIN>B002SQHNH2</ASIN> </Item> <Item> <ASIN>B0050C71PA</ASIN> </Item> <Item> <ASIN>B007XFXBII</ASIN> </Item> <Item> <ASIN>B00BMZ8NO2</ASIN> </Item> <Item> <ASIN>B00C5VMJEC</ASIN> </Item> <Item> <ASIN>B002SQHVE2</ASIN> </Item> <Item> <ASIN>B007XGUGSU</ASIN> </Item> </Items> </ItemSearchResponse>
10.但是还是要想办法,把剩余的5页的内容,都得到才可以。
继续参考:
http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemSearch.html
去添加
Retrieves a specific page of items from all of the items in a response. Up to ten items are returned on a page unless Valid Values: 1 to 10 (1 to 5 when the search index = "All") Type: String Default: None |
试试:
//reqDict["SearchIndex"] = "None"; reqDict["SearchIndex"] = "HomeGarden"; reqDict["ResponseGroup"] = "ItemIds"; //Home & Kitchen -> Heating, Cooling & Air Quality -> Air Conditioners & Accessories -> Energy Star Qualified //reqDict["BrowseNodeId"] = "3737761"; reqDict["BrowseNode"] = "3737761"; reqDict["ItemPage"] = "6";
结果为:
<?xml version="1.0"?> <ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <OperationRequest> <RequestId>3f7ae8d0-0bd8-4a65-9217-20e2b1916549</RequestId> <Arguments> <Argument Name="Operation" Value="ItemSearch"/> <Argument Name="Service" Value="AWSECommerceService"/> <Argument Name="Signature" Value="YdQU63MVS790IbwOm7qiilymkHNQu0qZthubgvx/JPw="/> <Argument Name="ItemPage" Value="6"/> <Argument Name="AssociateTag" Value="xxx"/> <Argument Name="BrowseNode" Value="3737761"/> <Argument Name="Version" Value="2011-08-02"/> <Argument Name="AWSAccessKeyId" Value="xxx"/> <Argument Name="Timestamp" Value="2013-06-13T13:23:22Z"/> <Argument Name="ResponseGroup" Value="ItemIds"/> <Argument Name="SearchIndex" Value="HomeGarden"/> </Arguments> <RequestProcessingTime>0.1727870000000000</RequestProcessingTime> </OperationRequest> <Items> <Request> <IsValid>True</IsValid> <ItemSearchRequest> <BrowseNode>3737761</BrowseNode> <ItemPage>6</ItemPage> <ResponseGroup>ItemIds</ResponseGroup> <SearchIndex>HomeGarden</SearchIndex> </ItemSearchRequest> </Request> <TotalResults>51</TotalResults> <TotalPages>6</TotalPages> <MoreSearchResultsUrl>http://www.amazon.com/gp/redirect.html?camp=2025&creative=386001&location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fsearch%3Fnode%3D3737761%26url%3Dsearch-alias%253Dgarden&linkCode=xm2&tag=xxx&SubscriptionId=xxx</MoreSearchResultsUrl> <Item> <ASIN>B00A03QHJA</ASIN> </Item> </Items> </ItemSearchResponse>
的确,是得到了所希望的数据:
之前显示共6页,共51个,每页10个,所以第6页,就只有1个。
如此,基本的功能:
查找浏览某个主分类,以及下面的子分类
以及子分类中,查找产品
就都基本跑通了。
【总结】
相对来说,还是不错的。
剩下就是写解析代码,实现对应的逻辑了。