【问题标题】:Amazon XML: Search for a products and return the results including priceAmazon XML:搜索产品并返回包括价格在内的结果
【发布时间】:2013-01-30 07:06:19
【问题描述】:

我正在尝试做非常简单的事情,我只需要在 Amazon 中搜索并返回包含产品、描述和价格的 XML。 这是我发送的最终地址:

http://webservices.amazon.com/onca/xml?AWSAccessKeyId=[MYKEYID]&AssociateTag=[MYASSOCIATION-TAG]&Keywords=Wireless%2520headset%2520xbox&Operation=ItemSearch&ReponseGroup=Full&SearchIndex=ALL&Service=AWSECommerceService&Timestamp=2013-01-29T21%3A04%3A49Z&Version=2011-08-01&Signature=[MY SIGNATURE]

除了价格之外,我几乎得到了所有东西:

<XML .... >
<item>...</item>
<Item><ASIN>B003ZSP0WW</ASIN><ParentASIN>B001ELJPOQ</ParentASIN><DetailPageURL>http://www.amazon.com/Xbox-360-Wireless-Controller-Glossy-Black/dp/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB003ZSP0WW</DetailPageURL><ItemLinks><ItemLink><Description>Technical Details</Description><URL>http://www.amazon.com/Xbox-360-Wireless-Controller-Glossy-Black/dp/tech-data/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Add To Baby Registry</Description><URL>http://www.amazon.com/gp/registry/baby/add-item.html%3Fasin.0%3DB003ZSP0WW%26SubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Add To Wedding Registry</Description><URL>http://www.amazon.com/gp/registry/wedding/add-item.html%3Fasin.0%3DB003ZSP0WW%26SubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Add To Wishlist</Description><URL>http://www.amazon.com/gp/registry/wishlist/add-item.html%3Fasin.0%3DB003ZSP0WW%26SubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>Tell A Friend</Description><URL>http://www.amazon.com/gp/pdp/taf/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>All Customer Reviews</Description><URL>http://www.amazon.com/review/product/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink><ItemLink><Description>All Offers</Description><URL>http://www.amazon.com/gp/offer-listing/B003ZSP0WW%3FSubscriptionId%3DAKIAJZRJGNZYA3M3E75Q%26tag%3DEBAZONSALE-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D386001%26creativeASIN%3DB003ZSP0WW</URL></ItemLink></ItemLinks><ItemAttributes><Manufacturer>Microsoft Software</Manufacturer><ProductGroup>Video Games</ProductGroup><Title>Xbox 360 Wireless Controller - Glossy Black</Title></ItemAttributes>
</Item>

请帮忙,我应该怎么做才能看到产品价格?有没有更简单的方法来解析亚马逊的价格?

谢谢!

【问题讨论】:

    标签: php xml-parsing amazon-web-services amazon


    【解决方案1】:

    尝试将&amp;ReponseGroup=Full 更改为&amp;ReponseGroup=Large,您将获得全部数据,但它也包括价格。它将在属性标签中。

    注意:尝试将其更改为 &amp;ReponseGroup=Small 您将获得较少的数据,但我不确定价格是否存在。

    这是亚马逊产品广告 API 的代码

    <?php
    error_reporting(0);
    
    define('AWS_API_KEY', 'your key');
    define('AWS_API_SECRET_KEY', 'your key');
    define('AWS_ASSOCIATE_TAG', 'your tag');
    define('AWS_ANOTHER_ASSOCIATE_TAG', '');
    
    define('PRODUCT_NUMBER', 20);
    
      require('./lib/AmazonECS.class.php');
    
    
    $category                   = $_REQUEST['category'];
    $search                     = $_REQUEST['search'];
    $page                       = (isset($_REQUEST['page']) && $_REQUEST['page'] != 0)?$_REQUEST['page']:1;
    
    try
    {
        $amazonEcs              = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'com', AWS_ASSOCIATE_TAG);
    
        $amazonEcs->associateTag(AWS_ASSOCIATE_TAG);
        $amazonEcs->returnType(AmazonECS::RETURN_TYPE_ARRAY);
    
        $response               = $amazonEcs->responseGroup('Large')->page(1)->category($category)->search($search);
        $page_count             = ceil(PRODUCT_NUMBER/10);
        $page_offset            = ($page-1)*$page_count+1;
        if($response['Items']['TotalPages'] <= $page_count){
             $page_count        = $response['Items']['TotalPages'];
        }
        $array_result           = array();
        for($i=$page_offset; $i<($page_count+$page_offset); $i++){
            $response_nxt       = $amazonEcs->responseGroup('Large')->page($i)->category($category)->search($search);
            $result_temp        = array_merge($array_result, $response_nxt['Items']["Item"]);
            $array_result       = $result_temp;
        }
        echo "<pre>";
        print_r($array_result);
    
    }
    catch(Exception $e)
    {
      echo $e->getMessage();
    }
    ?>
    

    【讨论】:

    • 否 :( 我仍然看不到价格.. 有什么想法吗?你能把我可以看到价格的 URL 发给我吗(我只是换个钥匙).. 谢谢!!
    • 我使用产品广告 API 来获取产品,你想要那个代码吗?
    • 您获得的响应不是 xml,而是 JSON,一次只能获得 10 个产品,您需要循环请求更多产品,询问您是否需要更多帮助或我的代码。跨度>
    • 能否请您简单地复制并粘贴此 JSON 搜索功能?谢谢!
    • 非常感谢!它的工作原理是,在原始演示 (amazonecs.pixel-web.org/…) 中,它从搜索中返回了这个数组:在 mien,我看到了数组本身 (Array ( [0] => Array ( [ASIN] => B0035FZJHQ [ParentASIN] => B005MUHJ4I) 你也有这个解析代码吗?不管怎样,非常感谢你的帮助!!
    猜你喜欢
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-26
    • 2017-07-27
    • 2012-08-23
    • 1970-01-01
    • 2017-06-17
    相关资源
    最近更新 更多