WebService::GoogleHack::Search - This module is used to query Google.


WebService-GoogleHack documentation Contained in the WebService-GoogleHack distribution.

Index


Code Index:

NAME

Top

WebService::GoogleHack::Search - This module is used to query Google.

SYNOPSIS

Top

    use WebService::GoogleHack::Search;

    #create an object of type search
    my $search = GoogleHack::Search->new();

    #Query Google.
    $search->searchPhrase($searchString);

    #The results variable will now contain the results of your query.

    #Printing the searchtime

    print "\n Search Time".$search->{'searchTime'};

    #Printing the snippet element 0

    print "\n\nSnippet".$search->{'snippet'}->[0];

DESCRIPTION

Top

This module provides a simple interface to the Google API. It is used by the GoogleHack module.

PACKAGE METHODS

Top

_METHOD__->new()

Purpose: This function creates an object of type Search and returns a blessed reference.

_METHOD__->init(key,wsdl_location)

Purpose: This this function can used to inititalize the member variables.

Valid arguments are :

_METHOD__->Search(searchString,num_results,integer)

Purpose: This function is used to query googles

Valid arguments are :

Returns: Returns a Search object containing the search results.

_METHOD__->getEstimateNo()

Purpose: This function returns the number of results predicted by google for a specific search term.

No Valid arguments.

Returns: Returns the total number of results for a search string..

_METHOD__->IamFeelingLucky()

Purpose: This function imitates the "I am Feeling Lucky" search feature of Google. It basically returns the URL of the first result of your search.

No Valid arguments.

Returns: Returns the URL of the first result of your search.

_METHOD__->getCachedPage()

Purpose: This function retrieves a cached webpage, given the URL.

No Valid arguments.

Returns: Returns the contents of as web page given a URL.

AUTHOR

Top

Pratheepan Raveendranathan, <rave0029@d.umn.edu>

Ted Pedersen, <tpederse@d.umn.edu>

BUGS

Top

SEE ALSO

Top

GoogleHack home page - http://google-hack.sourceforge.net

Pratheepan Raveendranathan - http://www.d.umn.edu/~rave0029/research

Ted Pedersen - www.d.umn.edu./~tpederse

Google-Hack Maling List <google-hack-users@lists.sourceforge.net>

COPYRIGHT AND LICENSE

Top


WebService-GoogleHack documentation Contained in the WebService-GoogleHack distribution.

#!/usr/local/bin/perl 

package WebService::GoogleHack::Search;

our $VERSION = '0.15';
use SOAP::Lite;


sub new
{
my $this = {};

$this-> {'Key'} = undef;
$this-> {'File_Location'} = undef;
$this-> {'yahooid'}=undef;
$this-> {'maxResults'} =10;
$this-> {'StartPos'} =0;
$this-> {'Filter'} ="false";
$this-> {'Restrict'} ="";
$this-> {'safeSearch'} ="false";
$this-> {'lr'} ="";
$this-> {'oe'} ="";
$this-> {'ie'} ="";
$this-> {'NumResults'} = undef;
$this-> {'snippet'} = undef;
$this-> {'searchTime'} = undef;
$this-> {'url'} = undef;
$this-> {'cachedPage'} = undef;
$this-> {'title'} = undef;


bless $this;

return $this;
}




sub init
{
my $this = shift;

$this->{'Key'} = shift;
$this->{'File_Location'} = shift;
$this-> {'yahooid'}= shift;
$this-> {'maxResults'} =shift;
$this-> {'StartPos'} =shift;
$this-> {'Filter'} =shift;
$this-> {'Restrict'} =shift;
$this-> {'safeSearch'} =shift;
$this-> {'lr'} =shift;
$this-> {'oe'} =shift;
$this-> {'ie'} =shift;

}

# this functions sets the maximum number of results retrived
sub setMaxResults
{
    my $this = shift;
    $maxResults = shift;

    $this-> {'maxResults'} =$maxResults;


}


sub setlr
{
    my $this = shift;
    $lr = shift;

    $this-> {'lr'} =$lr;


}

sub setoe
{
    my $this = shift;
    $oe = shift;

    $this-> {'oe'} =$oe;


}

sub setie
{
    my $this = shift;
    $ie = shift;

    $this-> {'ie'} =$ie;


}

sub setStartPos
{
    my $this = shift;
    $StartPos = shift;

    $this-> {'StartPos'} =$StartPos;


}

sub setFilter
{
    my $this = shift;
    $Filter = shift;

    $this-> {'Filter'} =$Filter;


}

sub setRestrict
{
    my $this = shift;
    $Restrict = shift;

    $this-> {'Restrict'} =$Restrict;


}

sub setSafeSearch
{
    my $this = shift;
    $Restrict = shift;

    $this-> {'Restrict'} =$Restrict;


}

sub searchPhrase
{
    my $searchInfo=shift;
    my $searchString=shift;
    my $num_results=shift;
    @snippet_array=();
    @url_array=();
    @title_array=();

    $count1=0;
    $count2=0;
    $count3=0;

    if(!defined($num_results))
    {
	$num_results=10;
    }

    print ".";
    $key  = $searchInfo->{'Key'}; 
    $wsdl_path =$searchInfo->{'File_Location'}; 

    
    print "\n Key is $key";
    print "\n path is $wsdl_path";
    print "\n Search phrase is $searchString\n";
#    print  $searchInfo-> {'StartPos'};
    
# Initialise with local SOAP::Lite file
    

open(WSDL,"$wsdl_path") || die("\n\n\n\nIllegal WSDL File Location : $wsdl_path\n\n\n\n");
close(WSDL);

$service = SOAP::Lite
    -> service("file:$wsdl_path");

$count=0;
   $searchInfo-> {'lr'}="lang_en";
 
while( $count < $num_results)

{
$result =  $service -> doGoogleSearch(
		      $key,                               # key
		      $searchString,                      # search query
		      $searchInfo-> {'StartPos'} + $count,# start results
		      $searchInfo-> {'maxResults'},       # max results
		      $searchInfo-> {'Filter'},           # filter: boolean
		      $searchInfo-> {'Restrict'},         # restrict (string)
		      $searchInfo-> {'safeSearch'},       # safeSearch: boolean
		      $searchInfo-> {'lr'},               # lr
		      $searchInfo-> {'oe'},               # ie
		      $searchInfo-> {'ie'}                # oe
		      );

foreach $temp (@{$result->{resultElements}}) {
  
 

    if(defined($temp->{URL}))
    {
	$url_array[$count2++]=$temp->{URL};      
    }
    else
    {
	$url_array[$count2++]="Undefined URL";
	
    }
    

    if(defined($temp->{title}))
    {
	$title_array[$count3++]=$temp->{title};
    }
    else
    { 
	$title_array[$count3++]="Undefined Title";
    }


    if(defined($temp->{snippet}))
    {
	$snippet_array[$count1++]=$temp->{snippet};
    }
    else
    { 
	$snippet_array[$count1++]="Undefined Snippet";
    }

#print "\n\n",$temp->{title};
#print "\n", $temp->{snippet};
#print "\n",$temp->{URL};


}


$count=$count+10;

}

$this->{'NumResults'} = $result->{estimatedTotalResultsCount};
$this->{'searchTime'} = $result->{searchTime};
$this->{'snippet'} = \@snippet_array;
$this->{'url'}=\@url_array;
$this->{'title'}=\@title_array; 

return $this;


}


sub getEstimateNo
{
    my $this = shift;

return   $this-> {'NumResults'};

}

sub IamFeelingLucky
{
   my $this = shift;
   return   $this->{'url'}->[0];
   
}



sub getCachedPage
{
    my $searchInfo=shift;
    $url=shift;
    
    $key  = $searchInfo->{'Key'}; 
    $wsdl_path =$searchInfo->{'File_Location'}; 
    
    
    $service = SOAP::Lite
	-> service("file:$wsdl_path");
    
    $cached = $service->doGetCachedPage($key,$url);
    
    #  print "\n\nDid you mean: $correction \n";
    if($cached)
    {
	require WebService::GoogleHack::Text;
	$cached=WebService::GoogleHack::Text::removeHTML($cached);
    }

    if($cached)
    {  
	$this-> {'cachedPage'} = $cached;
	return $cached;
    }
    
    
}



# remember to end the module with this
1;