自分のブログで紹介した全アマゾン商品のリストを作りました。
2004年分と2005年分です。
- 2004年 http://nais.to/~yto/amazon/clog04.html
- 2005年 http://nais.to/~yto/amazon/clog05.html
ブログのHTMLからASINだけ抜き出して、各ASINごとにAWSで
タイトルを取り出しリンクを作るだけです。
以下、作成に使ったソースコードです。
asin2li.pl
使い方メモ:
面倒なのでそこまでしなかったけど。
2004年分と2005年分です。
- 2004年 http://nais.to/~yto/amazon/clog04.html
- 2005年 http://nais.to/~yto/amazon/clog05.html
ブログのHTMLからASINだけ抜き出して、各ASINごとにAWSで
タイトルを取り出しリンクを作るだけです。
以下、作成に使ったソースコードです。
asin2li.pl
#!/usr/local/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $SID = 'XXXXXXXXXXXXXXXXXXXX';
my $AID = '137439-22';
while (<>) {
/^([0-9A-Z]{10})/ or next;
my $asin = $1;
my $title = get_amazon_title($asin);
next unless ($title);
print << "RV"
<li><a
href="http://www.amazon.co.jp/exec/obidos/ASIN/$asin/$AID/ref=nosim"
target="_blank">$title</a>
<span style="font-size:x-small">
(<a href="http://yasazon.com/$asin"
targe="_blank"><b>$title</b>\xe3\x82\x92Blog\xe3\x81\xa7
\xe7\xb4\xb9\xe4\xbb\x8b\xe3\x81\x99\xe3\x82\x8b</a>)
</span>
RV
;
}
sub get_amazon_title {
my ($asin) = @_;
my $ua = new LWP::UserAgent;
my $url = qq(http://webservices.amazon.co.jp/onca/xml?).
qq(Service=AWSECommerceService&SubscriptionId=$SID&).
qq(AssociateTag=$AID&Operation=ItemLookup&ItemId=$asin&).
qq(ResponseGroup=Small);
my $buf= $ua->get($url)->content;
my ($title) = ($buf =~ m!<Title>(.+?)</Title>!);
return $title;
}
入力は一行一ASINのファイル。出力はタイトル入りリンク(Yasazon付き)。使い方メモ:
% perl -ne 'while(m!/([0-9A-Z]{10})/!g){print "$1\n"}' \
~/www/clog/2004-??.html|sort -u>clog-asin-2004.txt
% ./asin2li.pl clog-asin-2004.txt > clog04.html
で、後はエディタで。ソースにテンプレート埋め込んでもいいね。面倒なのでそこまでしなかったけど。
