Created
February 18, 2010 08:26
-
-
Save makotoworld/307476 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Perl6::Say; | |
use Data::Dumper; | |
use LWP::UserAgent; | |
use XML::Simple; | |
use Encode; | |
my $keyword = shift; | |
$keyword = decode("shift-jis", $keyword); | |
my $kakaku = "http://api.kakaku.com/WebAPI/ItemSearch/Ver1.0/". | |
"ItemSearch.aspx?resultset=mini&ApiKey=c5ae3c2350a35ada450535c45881d9d9&SortOrder=pricerank&Keyword=".$keyword; | |
my $ua = LWP::UserAgent->new(); | |
$ua->agent('Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); | |
$ua->timeout(15); | |
$ua->proxy(['http'], 'http://10.6.64.10:8080'); | |
my $res = $ua->get($kakaku); | |
$res->is_success or die 'Can\'t connect to api.kakaku.com'; | |
my $xml_parser = XML::Simple->new(); | |
$XML::Simple::PREFERRED_PARSER = 'XML::Parser'; | |
my $xml = $res->content; | |
my $data = XMLin($xml); | |
#say Dumper($data); | |
#say $data->{Item}; | |
#say defined($data->{Item}[0]); | |
#say defined(@{$data->{Item}}); | |
foreach ( @{$data->{Item}} ){ | |
unless (ref $_->{'LowestPrice'}){ | |
say Encode::encode("shift-jis",$_->{'ProductName'})," \\",$_->{'LowestPrice'}; | |
say $_->{'ItemPageUrl'}."\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment