
mike
User
Jun 29, 2001, 7:31 PM
Post #1 of 8
(3960 views)
|
Help With Meta Search
|
Can't Post
|
|
Hello, I was wondering if someone could help me out. I have had this meta search engine running on my site for a while now, and it all of a sudden won't work anymore. This is the coding I am using, I would appreciate some help, it has been driving me insane :) This is what I have without the Form html ------------------------------------------------- &data_parse; &main; sub main{ $| = 1; if ($FORM{'q'} eq '') { &show(); exit; } &IOSocket; $output = join(" ", @output); $output =~ /([^ ]*?) pages found\./i; $total = $1; $total =~ s/[^\d+]//g; ($rsltpgs, @results, $footer) = split(/<dl>/i, $output); $FORM{'nh'} = 0 unless($FORM{'nh'}); $prev = $FORM{'nh'} - 10; $next = $FORM{'nh'} + 10; $rsltpgs = qq~<p><font size=-1><b>Results Pages:\ </b>~; $rsltpgs .= qq~<a href="$ENV{'SCRIPT_NAME'}?q=$query&nh=$prev&user=$FORM{'user'}">[<b>\<\< Prev</b>]</a>~ if ($prev >= 0); $Remainder = $total % 10; $Remainder = 10 - $Remainder; $Results_Pages = ($total + $Remainder) / 10; $Results_Pages = 20 if ($Results_Pages > 20); for ($i = 1; $i <= $Results_Pages; $i++) { $nh = ($i - 1) * 10; if ($nh == $FORM{'nh'}) { $rsltpgs .= qq~\ \ <b>$i</b>\ ~; } else { $rsltpgs .= qq~\ \ <a href="$ENV{'SCRIPT_NAME'}?q=$query&nh=$nh&user=$FORM{'user'}">$i</a>\ ~; } } $rsltpgs .= qq~\ \ <a href="$ENV{'SCRIPT_NAME'}?q=$query&nh=$next&user=$FORM{'user'}">[<b>Next \>\></b>]</a>~ if ($next < $total && $FORM{'nh'} < 190); $rsltpgs .= qq~</font> ~; $start = $FORM{'nh'} + 1; $end = $start + 9; $end = $total if ($end > $total); $output = "<font face=arial size=2><b>Showing results $start - $end of $total</b> Results Provided By <a href=http://www.altavista.com>Altavista</a></font>$rsltpgs<ul>\n"; my $last = $#results - 1; for(0..$last){ ($result) = split(/<\/dl>/i, $results[$_]); $result =~ s/\[[^\]]\]//ig; $result =~ /<a\s+href=\"([^\"]*?)\">/ig; $url = $1; ($tmp, $title) = split(/\">/i, $result); ($title, $tmp) = split(/<\/a>/i, $title); ($ttp, $desc) = split(/<dd>/i, $tmp); ($desc, $tmp) = split(/ /i, $desc); $output .= qq~<li><a href="$url">$title</a> - $desc<p>\n~; } $output .= qq~</ul>$rsltpgs~; &show($start,$stop,$command,$input,$output,$special); } sub IOSocket{ use IO::Socket; $method = "GET"; my @f = split(/\//, $input); $host = "www.altavista.com"; $path = "/sites/search/web?q=$query&pg=q&text=yes&kl=XX&stq=$FORM{'nh'}&search=Search"; $socket = new IO::Socket::INET( PeerAddr => $host, PeerPort => 80, Proto => 'tcp', Type => SOCK_STREAM, ) or die &show($start,$stop,$command,$input,"<p>Error: Unable to connect to search server<p>",$special); print $socket "$method $path HTTP/1.0\nReferer: $host\n"; print $socket "User-Agent: $ENV{'HTTP_USER_AGENT'}\n\n"; @output = <$socket>; close ($socket); } sub data_parse{ if ($ENV{"REQUEST_METHOD"} eq 'GET') { $buffer = $ENV{'QUERY_STRING'}; } else { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); if ($name eq 'q'){ $query = $value; } $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/>//g; $value =~ s/<//g; $FORM{$name} = $value; } $FORM{'q'} = $FORM{'search'} if $FORM{'search'}; } Thanks for the help. Mike
|