Hi junko,
I try to pull out the links but still blank, the page only show the spanning without result, that mean there was something i forgot to code the script:
sub altavista {
# --------------------------------------------------------
# Search Altavista
my %in = &parse_form;
use LWP::Simple;
# Boolean Options
if ($in{'bool'} eq 'and') {$bool = '+AND';}
elsif ($in{'bool'} eq 'or') {$bool = '+OR';}
else {$bool = '';}
if (!$in{'query'}) { &site_html_search_failure ("Please enter one or more keywords.") and exit; }
# Define Variables
my $page = ($in{'page'} * 10) || 0;
my $pageXX = $page - 10;
my $query = $in{'query'};
my $query_q = &urlencode($query);
my $url = "http://web.altavista.com/cgi-bin/query?q=$query_q";
my $results = get ($url);
my $FONT = 'font face="verdana, arial" size="2"';
my $FONT_SMALL = 'font face="verdana, arial" size="1"';
$results or &site_html_search_failure ("There are no results available!") and exit;
# If we see this, then we couldn't get a match.
if ($results =~ /AltaVista found no document matching your query./) {
&site_html_search_failure ("No matching AltaVista links!") and exit;
}
else {
if ($results =~ /We found ([^>\s]+) results:/) { $link_hits2 = $1; }
else { &site_html_search_failure ("Can't parse AltaVista results!") and exit; }
# Remove Bolded text
while ($results =~ m#<b>#sog) {
$results =~ s/<b>//gie;
$results =~ s/<\/b>//gie;
}
while ($results =~ m#
#sog) {
$results =~ s/
//gie;
$results =~ s/
//gie;
}
while ($results =~ m#<span class=x>#sog) {
$results =~ s/<span class=x>//gie;
$results =~ s/<span class=x>//gie;
}
while ($results =~ m#<EM>#sog) {
$results =~ s/<EM>//gie;
$results =~ s/<\/EM>//gie;
}
$count = 0;
# Pull out the links
while ($results =~ m|
href="([^"]+)" onMouseOver="status='([^']+)'\; return true\;">([^<]+)</a> <span id="(\d+)" class=y></span>\n
\n([^<]+)|sog) {
$count+1;
($count, $title, $url, $description) = ($1, $2, $3, $4);
$url2 =~ s/\s//gie;
$url2 = qq|http://$url2|;
%tmp = ("Count", $count, "URL", $url, "Title", $title, "Description", $description, "URL2", $url2);
$link_results2 .= &site_html_altavista_link (%tmp) . "\n";
}
}
$next2 = &next_hits($page, $link_hits2, 10);
# Bold Search Terms
@search_terms = split (/\s/, $in{'query'});
if (($in{'bold'} == 0) or (!$in{'bold'})) {
foreach $term (@search_terms) {
$link_results2 =~ s,(<[^>]+>)|(\Q$term\E),defined($1) ? $1 : "<STRONG>$2</STRONG>",gie;
}
}
if ($in{'search'} eq "both") { return; }
&site_html_search_results;
exit;
}
sub next_hits {
# --------------------------------------------------------
# Creates a next hits toolbar.
#
my ($page, $numhits, $maxhits) = @_;
my ($left, $right, $upper, $lower, $next_hit, $prev_hit, $i);
my $nh = int ($page / $maxhits) || 1;
my $output = '';
$numhits =~ s/,//g;
$numhits = int ($numhits);
$next_url = $ENV{'QUERY_STRING'};
$next_url =~ s/\&page=\d+//;
$next_hit = $nh + 1;
$prev_hit = $nh - 1;
# First, set how many pages we have on the left and the right.
$left = $nh;
$right = int($numhits/$maxhits) - $nh;
# Then work out what page number we can go above and below.
($left > 7) ? ($lower = $left - 7) : ($lower = 1);
($right > 7) ? ($upper = $nh + 7) : ($upper = int($numhits/$maxhits) + 1);
# Finally, adjust those page numbers if we are near an endpoint.
(7 - $nh >= 0) and ($upper = $upper + (8 - $nh));
($nh > ($numhits/$maxhits - 7)) and ($lower = $lower - ($nh - int($numhits/$maxhits - 7) - 1));
# Then let's go through the pages and build the HTML.
($nh > 1) and ($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&page=$prev_hit">[<<]</a> ~);
for ($i = 1; $i <= int($numhits/$maxhits) + 1; $i++) {
if ($i < $lower) { $output .= " ... "; $i = ($lower-1); next; }
if ($i > $upper) { $output .= " ... "; last; }
($i == $nh) ?
($output .= qq~$i ~) :
($output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&page=$i">$i</a> ~);
(($i * $maxhits) >= $numhits) and print "Exiting3" and last; # Special case if we hit exact.
}
$output .= qq~<a href="$ENV{'SCRIPT_NAME'}?$next_url&page=$next_hit">[>>]</a> ~ unless ($nh == $i);
return $output;
}
Please help and thank you.