Amazonから情報を取得する


 Net::Amazonモジュールを使うと簡単です。別途Amazon Web ServicesからAccess KeyとSecret Access Keyを取得する必要があります。
use strict;
use warnings;
use Net::Amazon;
use encoding "cp932"; # 文字コードの指定

my $amazon = Net::Amazon->new(
    token => '取得したAccess Key',
    secret_key => '取得したSecret Access Key',
    locale => 'jp',
);

my $asin = ['4101327181']; # 検索対象ASIN
my $res = $amazon->search(asin => $asin); # ASINで検索する

unless ($res->is_success()) {
    # データ取得に失敗
    print $res->message(), "\n";
    exit;
}

foreach my $item ($res->properties) {
    print "Asin: ", $item->Asin, "\n";
    print "ProductName: ", $item->ProductName, "\n";
    print "Availability: ", $item->Availability, "\n";
    print "Catalog: ", $item->Catalog, "\n";
    print "Authors: ", join(', ', $item->authors), "\n"
        if $item->can('authors');
    print "ReleaseDate: ", $item->ReleaseDate, "\n";
    print "Manufacturer: ", $item->Manufacturer, "\n";
    print "ImageUrlMedium: ", $item->ImageUrlMedium, "\n";
    print "OurPrice: ", $item->OurPrice, "\n";
    print "Media: ", $item->Media, "\n";
    my $review = $item->review_set;
    if ($review->total_reviews) {
        print "\n";
        print "AverageCustomerRating: ",
            $review->average_customer_rating, "\n";
        foreach my $rev ($review->reviews) {
            print "Rating: ", $rev->rating, "\n";
            print "Summary: ", $rev->summary, "\n";
            print "Comment: ", $rev->comment, "\n";
        }
    }
    print "\n";
}

関連項目

なし