javascript Amazon API调用以获取页面上列出的产品数量

sqyvllje  于 2023-02-18  发布在  Java
关注(0)|答案(1)|浏览(77)

有没有可能在亚马逊页面中获得列出的产品计数?

我需要得到这个数字。我知道我可以使用javascript通过ID或类得到它,但我知道亚马逊在某段时间内会更改ID和类的值,所以以后我将无法得到这个数字,除非我自己检查ID或类并在代码中更改它。。那么是否有API调用或其他东西可以免费获得这个数字,而无需每次都更改代码?

k4emjkb1

k4emjkb11#

您需要ItemSearchResponseGroupBrowseNodes的组合。如果您使用C#并将结果传递回JavaScript应用,则会出现以下情况:

ItemSearchRequest request = new ItemSearchRequest();
request.ResponseGroup = new string[] { "BrowseNodes", "ItemAttributes" };
request.SearchIndex = "Movies";
request.Keywords = "game of thrones";

ItemSearch search = new ItemSearch();
search.AWSAccessKeyId = access_key_id;
search.AssociateTag = associate_tag;
search.Request = new ItemSearchRequest[] { request };

AWSECommerceServicePortTypeClient port = new AWSECommerceServicePortTypeClient("AWSECommerceServicePort");
port.ChannelFactory.Endpoint.EndpointBehaviors.Add(new AmazonSigningEndpointBehavior(access_key_id, secret_access_key));

ItemSearchResponse response = port.ItemSearch(search);
foreach (var items in response.Items)
{
    foreach (var item in items.Item)
    {
        Console.WriteLine("{0}\t{1}\t{2}", item.ItemAttributes.Title, item.ASIN, item.ItemAttributes.Author[0]);

        if (item.BrowseNodes != null)
        {
            Console.WriteLine(" - BrowseNodes");
            foreach (var node in item.BrowseNodes)
            {
                Console.WriteLine(" -- \t{0}\t{1}\t{2}", node.TotalResults);
            }
        }
    }
}

相关问题