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/<br>//g; $body.= "$x<br>\n" } $body.="<br><br>\n"; } print <<EOF; Content-type: text/html; charset=UTF-8 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head> <META http-equiv="Content-Type" content="text/html;"> <title>google web api test</title> </head> <body> $body </body> EOF </plaintext> </body> </html>