google対策入門
TECH EZO 勉強会
2003.11.28 TECH EZO 勉強会での
パワーポイント資料
google api のテストです。
CGIのソース
#!/usr/bin/perl
#use KCatch qw( execdata );__DATA__
use Jcode;
use SOAP::Lite;
my (%q, $body, $k, $result, $results, $x, $pair, $query);
my $google_key='0000000000000000000000000000000000'; # your key
my $google_wsdl="./GoogleSearch.wsdl";
my $query=$ENV{'QUERY_STRING'};
if($query=~/=/){
my @f=split("&",$query);
foreach $pair (@f) {
my($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$q{$name}=$value;
}
$query=$q{"q"};
}
$query=Jcode->new($q{"q"})->utf8();
my $google_search=SOAP::Lite->service("file:$google_wsdl");
$results=$google_search->
doGoogleSearch(
$google_key, $query, 0,10, "false", "", "false",
"", "utf8", "utf8"
);
for $result (@{$results->{resultElements}}){
for $k ("title","URL","snippet"){
$x=$result->{$k};
$x=~s/
//g;
$body.= "$x
\n"
}
$body.="
\n";
}
print <
google web api test
$body
EOF