Gossamer Forum
Home : Products : Links 2.0 : Customization :

Altavista.cgi can not get the links results

Quote Reply
Altavista.cgi can not get the links results
Today my altavista.cgi can not get the links results,
Just can received the pages no only.

Please Help Me Asap, Thanks.

Below is altavista.cgi source code.

################################################################# Start
#!/usr/bin/perl

use strict;
use CGI;
use LWP::Simple;

my $in = new CGI;

# Either display the source code, the search form or do the search.
defined $in->param('source') and &source();
defined $in->param('query') or &display_form();

# We are searching, so get the query, escape it, and use LWP to search.
my $query = $in->param('query');
my $query_q = &urlencode($query);
my $page = ($in->param('nh') * 10) || 0;
my $url = "http://www.altavista.com/cgi-bin/query?q=$query_q&text=yes&stq=$page";
my $results = get ($url);

# Couldn't connect, timed out, lots of possibilities.
$results or &error ("No results available.");

# If we see this, then we couldn't get a match.
my $none = quotemeta ("AltaVista found no document matching your query.");

my ($count, $title, $description, $url2, $last, $size);
my $output = '';
my $total = 0;

if ($results =~ m/$none/) {
$output = "No records were found.";
}
else {
# Altavista sometimes adds the word about for large sites.
if ($results =~ /<p>(\S+) pages found./) {
$total = $1;
}
elsif ($results =~ /(\S+) pages found./) {
$total = $1;
}
else {
$output = "Ooops, can't parse results: <pre>$results</pre>";
}

# Loop through the results pulling out each link.
if ($total) {
while ($results =~ m#<dl><dt>\n<b>(\d+)\.\s*</b>\n<a href="([^"]+)">\n<b>([^<]+)</b></a></dt>\n<dd>([^<]*)</dd>\n
<b>URL:</b> <font color="\#808080">([^<]+)</font>\n
<font color="\#808080">\n([^<]+)\n([^<]+)</font><?b?r?>?#sog) {
($count, $url, $title, $description, $url2, $last, $size) = ($1, $2, $3, $4, $5, $6, $7);
$output .= qq~<p><b>$count</b> - <a href="$url">$title</a>
$description
<font size=2 color=#666666></font>
~;
}
}
}

# Print the output.
print CGI->header;

my $next = &next_hits($page, $total, 10);
my $banner = &banner;

print qq~
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Link On Demand</title>
<style type="text/css">a:hover { color: #000066 }
</style>
<style>span.NOUNDERLINE { text-decoration: none }
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000CC" vlink="#0000CC" alink="#0000FF">

<center>



</form>


</center>
</div>
</div>
</form>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
</center><center>
<tr>
<td>
<div align="center">
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td bgcolor="#336699">
<p align="left"><font face="Arial"><b><font color="#ffffff">Search
Results </font></b><font color="#ffffff" size="2" face="Arial">Found<b>
$total </b>sites for <b>$query</b></font></font></p>
</td>
</tr>
</table>
</div>
</td>
</tr>
</center>
</tbody>
</table>
<p><center>$banner</center></p>
<table bgcolor="black" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<td>
<table border="0" cellpadding="2" cellspacing="1" width="100%">
<tbody>
<tr align="middle" bgcolor="#eeeeee">
<td bgcolor="#EEEEEE" width="33%"><font face="arial" size="-1" color="#FFFFFF"><a href="http://www.linkondemand.com/cgi-bin/links/search.cgi?query=$query">Categories</a></font></td>
<td bgcolor="#336699" width="33%"><font face="arial" size="-1" color="#FFFFFF"><b>Web
Sites</b></font></td>
<td width="33%"><font face="arial" size="-1">Personal Open
Directory</font></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<p align="center">$next</p>
<table border="2" bordercolor="#006600" cellpadding="3" cellspacing="0" height="66" width="120" align="right">
<tr>
<td align="middle" bgcolor="#ffffcc"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="-1">Amazon.com</font></b>

</td>
</tr>
<tr>
<td align="middle"><font face="Verdana, Arial, Helvetica, sans-serif" size="-2">Search
for:

<a href="http://www.amazon.com/exec/obidos/external-search/002-3472570-1267842?tag=linkondemandbook&mode=&keyword=$query">$query</a>

</font></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="75%">
<tr>
<td width="100%"> </td>
</tr>
<tr>
<td width="100%"><b><font size="2" face="Arial">Links</font></b></td>
</tr>
<tr>
<td width="100%" bgcolor="#336699"><img height="2" width="2"></td>
</tr>
<tr>
<td width="100%"> </td>
</tr>
</table>
<p align="center">$output</p>
<p align="center">$next</p>
<p>
<table border="2" cellpadding="3" cellspacing="0" bordercolor="#336699" width="100%">
<tr>
<td align="center" bgcolor="#336699" bordercolor="#FFFFFF"><b><font size="2" color="#FFFFFF" face="Verdana"><a href="http://www.linkondemand.com/"><span class="NOUNDERLINE"><font size="2" face="Verdana" color="#FFFFFF">Home</font></span></a></font></b></td>
<td align="center" bgcolor="#336699" bordercolor="#FFFFFF"><b><font face="Verdana" size="2"><a href="http://www.linkondemand.com/cgi-bin/links/add.cgi"><span class="NOUNDERLINE"><font size="2" face="Verdana" color="#FFFFFF">Add
a Link</font></span></a></font></b></td>
<td align="center" bgcolor="#336699" bordercolor="#FFFFFF"><b><font size="2" color="#FFFFFF" face="Verdana"><a href="http://www.linkondemand.com/cgi-bin/links/modify.cgi"><span class="NOUNDERLINE"><font size="2" face="Verdana" color="#FFFFFF">Modify
a Link</font></span></a></font></b></td>
<td align="center" bgcolor="#336699" bordercolor="#FFFFFF"><b><a href="http://www.linkondemand.com/New/"><span class="NOUNDERLINE"><font size="2" face="Verdana" color="#FFFFFF">What's
New</font></span></a></b></td>
<td align="center" bgcolor="#336699" bordercolor="#FFFFFF"><b><font size="2" color="#FFFFFF" face="Verdana"><a href="http://www.linkondemand.com/Cool/"><span class="NOUNDERLINE"><font size="2" face="Verdana" color="#FFFFFF">What's
Cool</font></span></a></font></b></td>
<td align="center" bgcolor="#336699" bordercolor="#FFFFFF"><b><font size="2" color="#FFFFFF" face="Verdana"><a href="http://www.linkondemand.com/Ratings/"><span class="NOUNDERLINE"><font size="2" face="Verdana" color="#FFFFFF">Top
Rated</font></span></a></font></b></td>
<td align="center" bgcolor="#FFFFFF" bordercolor="#000000"><b><span class="NOUNDERLINE"><font size="2" face="Verdana" color="#000000">Search</font></span></b></td>
</tr>
</table>
<p><center>$banner</center></p>
<p align="center"><font face="Verdana" size="1">Copyright © 1999
LinkOnDemand.com and its content providers. All Rights Reserved.

<a href="http://gossamer-threads.com/scripts/links/">Links Engine Powered By
Gossamer Threads</a></font></p>

</body>

</html>

~;

sub banner { my $ad = `/home/lod/cgi-bin/random/ads.cgi`;
$ad =~ s,Content-type:\stext/html,,;
return $ad;
}

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);

my $next_url = $ENV{'QUERY_STRING'};
$next_url =~ s/\&nh=\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&nh=$prev_hit">[<<]</a> ~);
for ($i = 1; $i <= int($numhits/$maxhits) + 1; $i++) {
last if ($i > 19);
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&nh=$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&nh=$next_hit">[>>]</a> ~ unless (($nh == $i) or ($nh == 19));
return $output;
}

sub display_form {
# ----------------------------------------------
print CGI->header('text/html');
print qq~
<form action="$ENV{'SCRIPT_NAME'}" METHOD=GET>
Search for: <input name=query>
</form>
~;
exit;
}

sub urlencode {
# --------------------------------------------------------
# Escapes a string to make it suitable for printing as a URL.
#
my($toencode) = shift;
$toencode =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%x",ord($1))/eg;
return $toencode;
}

sub error {
# ----------------------------------------------
print CGI->header('text/plain');
print "Error: $_[0]";
exit;
}


################################################################ End


Quote Reply
Re: Altavista.cgi can not get the links results In reply to
You should really search the forum first, this has been discussed extensively for the past week here

http://www.gossamer-threads.com/...w=collapsed&sb=5

and

http://www.gossamer-threads.com/...w=collapsed&sb=5

John

Quote Reply
Re: Altavista.cgi can not get the links results In reply to
That discuss is for search.cgi ,
I need is alavista.cgi , Thanks.

Quote Reply
Re: Altavista.cgi can not get the links results In reply to
Hi, I stripped down a huge file I made a while back and here are the results:

http://www.magicdirectory.com/...s-mods/altavista.txt

All you have to do is create a template (results.html) and insert these tags where you want them:

<%results%>
<%query%>
<%next%>
<%hits%>

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Altavista.cgi can not get the links results In reply to
Hi Jdgamble,

Thanks for your reply ,
I just need can run the altavista.cgi 1 file only,
That mind when u type http://www.url.com/altavista.cgi?anykeywords
Then u can get the anykeywords results , but now i can't get the result, before 1 month that script can run .

Thanks.



Quote Reply
Re: Altavista.cgi can not get the links results In reply to
jdgamble:
the script seems to be working fine but i'm getting the results in text file (like the source code) why do think i'm getting that. i must done something wrong with results.html.
if i want to put results.html in a differnt directory then i should change it in altavista.html to http://mysite.com/new/results.html
or /pathe/to/new/results.html

Zero One:
just use the same code you use to search the directory and change script name to altavista.cgi



Quote Reply
Re: Altavista.cgi can not get the links results In reply to
Zery One

Its http://www.url.com/altavista.cgi?query=keywords...

Right theguy...

Just change it to the path if you change the directory... also make sure you chmod results.html (777) if you want to be able to edit it online (frontpage extension users) and altavista.cgi (755) like any cgi script.

- Jonathan
http://www.magicdirectory.com/
Quote Reply
Re: Altavista.cgi can not get the links results In reply to
for some reason, i'm getting the results in text mode (like i'm looking at the page source)
i'm using raq3, could this be the reason? i'm switching to a linux server at the end of the month.
in tghe mean tine, is there a solution for this?


Quote Reply
Re: Altavista.cgi can not get the links results In reply to
If you have perl5 and you chmod your file 755, I don't see where that problem could occurr, then again, maybe it is your server...

- Jonathan
http://www.magicdirectory.com/