
my ($myquery) = @_;
print $socket ("GET $myquery HTTP/1.0\n\n");
while ($line = <$socket>)
{
if ($line =~ /Results.*of\sabout/)
{
return $line;
}
}
}
#Section 5
############################
sub getTotalHits($)
{
my ($ourline) = @_;
$hits="";
$index = index($ourline, "of about");
$str = substr($ourline, $index, 30);
@buf=split(//,$str);
for ($i = 0; $i < 30; $i++)
{
if ($buf[$i] =~ /[0-9]/)
{
$hits=$hits.$buf[$i];
}
}
return $hits;
}
############################
#Section 6
socketInit();
$string = sendQuery($query);
$totalhits = getTotalHits($string);
www.syngress.com
388 Chapter 12 • Automating Google Searches
315_PTG_12.qxd 11/22/04 12:18 PM Page 388