Link to home
Start Free TrialLog in
Avatar of sohaib69
sohaib69

asked on

perl search engine

dear sir, i need a perlscript by which i will search google.com search engine thru my web site, and
then the result will show on my web site just the results, how I am going to tdo this. could you please
tell me the perl or cgi script in order to search like that. Thanks.
Avatar of shlomoy
shlomoy

Just add this to the HTML in your web site

        <!-- Google -->
        <form name=srchform action="http://www.google.com/search" method="GET">
                <a href="http://www.google.com/">Google</a>
                <input type=text size="20" name=q>  
                <input type=hidden name=num value="100">
                <input type=submit name="action" value="Google">
        </form>
ASKER CERTIFIED SOLUTION
Avatar of shlomoy
shlomoy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sohaib69

ASKER

hi there, ihave install that WWW:SEARCH MODULE, and now after when i run that script it gave me internal server error , and my error log says :-

Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at google.cgi line 5.
[Sat Jun  2 20:12:39 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/google.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at google.cgi line 5.
[Sat Jun  2 20:12:40 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/google.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at google.cgi line 5.
[Sat Jun  2 20:12:41 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/google.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at google.cgi line 5.
[Sat Jun  2 20:12:42 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/google.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at google.cgi line 5.
[Sat Jun  2 20:12:43 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/google.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at google.cgi line 5.
[Sat Jun  2 20:12:44 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/google.cgi
Can't locate WWW/Search.pm...

Yes - you need to install it first.
Get it from:
http://search.cpan.org/search?dist=WWW-Search-Google
I install that module and its giving me that error Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at goog.cgi line 5.
[Sat Jun  2 20:27:03 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/goog.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at goog.cgi line 5.
[Sat Jun  2 20:27:06 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/goog.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at goog.cgi line 5.
[Sat Jun  2 20:27:07 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/goog.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at goog.cgi line 5.
[Sat Jun  2 20:27:08 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/goog.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at goog.cgi line 5.
[Sat Jun  2 20:27:09 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/goog.cgi
Can't locate WWW/Search.pm in @INC (@INC contains: /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_per$
BEGIN failed--compilation aborted at goog.cgi line 5.
[Sat Jun  2 20:27:10 2001] [error] [client 63.100.208.117] Premature end of script headers: /home/admin/www/cgi-bin/goog.cgi


One more thing when I do perl -v i got some error, on my server it says..

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = "en_US",
        LANG = "en_US"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

I think thats why its not coming up, what you think anyway how to get rid of that error.
Hi there, i have that following script but the thing is when ever I run that on my server its just give me powered by some one else, how I am going to get rid of that, u can see how I want my script to be, like the script is :-

===========================================================
#!/usr/bin/perl
#
# Zygit Co-Branding
# Free Style
# Copyright (c) 2001 Zygit Networks
#
#
use LWP::Simple;
use LWP::UserAgent;

&cgi_header;
&cgi_receive;

# The location of your header and footer (full path not the address)
$header = "/home/www/header.html";
$footer = "/home/www/footer.html";

# If you rename the script, be sure to update this line.  Use the
# URL address for this (http://www.you.ext/cgi-bin/search/metasearch.cgi)
$script_url = "metasearch.cgi";

# DO NOT EDIT THIS UNLESS YOU KNOW WHAT YOU ARE DOING!
#-----------------------------------------------------

$startpage = $FORM{startpage};
$search = $FORM{search};
$skip = $FORM{skip};

if ($startpage eq "") { $startpage = 1 ; }

open (HEADER, "$header");
      while (<HEADER>) { print; }


print <<EOF;
<center>
<form action="$script_url"><input type=text name=search value=$search><input type=submit value=Search></form>
<br><a name=top>
</center>
EOF


if ($search eq "") {
      exit(0);
} else {
      $url = "http://www.zygit.com/cgi-bin/search/metasearch.pl?etype=web&search=$search&logfile=searches&startpage=$startpage";
}

        my $ua = new LWP::UserAgent;
        my $res = $ua->request(HTTP::Request->new(GET => $url));
        my $content = $res->content;

@page = split(/\n/,$content);
for (@page){
      $_ =~ s/#99CCCC/$header_color/g;
      $_ =~ s/metasearch.pl/$script_url/g;
      $_ =~ s/name="query"/name=search/g;
      if ($_ =~ /<!--pull -->/) { $print = "on"; }
      if ($_ =~ /<!--stop -->/) { $print = "off"; }
      if ($print eq "on") { print "$_\n"; }
}
print <<EOF;
<center>
<form action="$script_url"><input type=text name=search> <input type=submit value=Search></form>
<br><a name=top>
</center>
EOF


sub parse_form {

   # Get the input
   read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

   # Split the name-value pairs
   @pairs = split(/&/, $buffer);

   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);

      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $FORM{$name} = $value;
   }
}

open (FOOTER, "$footer");
      while (<FOOTER>) { print; }

# DO NOT TOUCH THIS!

sub cgi_header {
    print "Content-type: text/html\n";
    print "\n" unless ($FORM{'next-url'});
}        

sub cgi_receive {
    if ($ENV{'REQUEST_METHOD'} eq "POST") {
        read(STDIN, $incoming, $ENV{'CONTENT_LENGTH'});
    }
    else {
        $incoming = $ENV{'QUERY_STRING'};
    }
    @pairs = split(/&/, $incoming);

    foreach (@pairs) {
        ($name, $value) = split(/=/, $_);

        $name  =~ tr/+/ /;
        $value =~ tr/+/ /;
        $name  =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie;
        $value =~ s/%([A-F0-9][A-F0-9])/pack("C", hex($1))/gie;

        #### Strip out semicolons unless for special character
        $value =~ s/;/$$/g;
        $value =~ s/&(\S{1,6})$$/&\1;/g;
        $value =~ s/$$/ /g;

        $value =~ s/\|/ /g;
        $value =~ s/^!/ /g; ## Allow exclamation points in sentences

        #### Skip blank text entry fields
        next if ($value eq "");

        #### Check for "assign-dynamic" field names
        #### Mainly for on-the-fly input names, especially checkboxes
        if ($name =~ /^assign-dynamic/) {
            $name = $value;
            $value = "on";
        }

      #### Allow for multiple values of a single name
        $FORM{$name} .= ", " if ($FORM{$name});

        $FORM{$name} .= $value;
    }
}
===========================================================

you can see the example at

http://www.wcws.net/metasearch.cgi?search=saasoh

I want something like that  . .

could you please help me but the thing is I dont want anything like Powered by: Zygit Networks

I want jut the results how I am going to get rid of that . Thanks
     1 #!/usr/bin/perl -w
      2 use strict;
      3 use CGI qw/:standard/;
      4 $|++;
      5 use WWW::Search;
      6 my $Search = new WWW::Search('Google');
      7 my $Query = WWW::Search::escape_query(param('query'));
      8 $Search->native_query($Query);
      9 print header,start_html("Google Results"),h1("Google Results:");
     10 while (my $Result = $Search->next_result()) {
     11         print "<a href='",$Result->url,"'>",$Result->url, "<br>\n";
     12 }
     13 print end_html;        
i dont think there is a difference after you post that above script, same thing is happening..

i cant see the next page link nor the thing like

1- COMPANY NAME OF SEARCH