Solved

perl search engine

Posted on 2001-06-02
10
464 Views
Last Modified: 2011-04-14
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.
0
Comment
Question by:sohaib69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 8

Expert Comment

by:shlomoy
ID: 6149850
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>
0
 
LVL 8

Accepted Solution

by:
shlomoy earned 50 total points
ID: 6149856
Alternatively, use this HTML file and CGI script:

search_google.html:
===================
      1 <html><head><title>Search Google</title></head>
      2 <body>
      3         <h1>Search Google</h1>
      4         <!-- Google -->
      5         <form name="searchform" action="cgi-bin/search_google.cgi.pl" method="GET">
      6                 <a href="http://www.google.com/">Google</a>
      7                 <input type=text size="20" name="query">
      8                 <input type=hidden name=num value="100">
      9                 <input type=submit name="action" value="Google">
     10         </form>
     11
     12 </body>
     13 </html>          



search_google.cgi.pl:
======================
      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 $Result->url, "\n";
     12 }
     13 print end_html;                  



you will need two Perl modules:

CGI and WWW::Search::Google
Both are available through http://search.cpan.org/
0
 
LVL 1

Author Comment

by:sohaib69
ID: 6149966
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:shlomoy
ID: 6149980
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
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6149983
0
 
LVL 1

Author Comment

by:sohaib69
ID: 6149991
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.
0
 
LVL 1

Author Comment

by:sohaib69
ID: 6150203
0
 
LVL 1

Author Comment

by:sohaib69
ID: 6150211
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
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 6150212
     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;        
0
 
LVL 1

Author Comment

by:sohaib69
ID: 6150231
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question