Re: $ua->no_visits() problem

Gisle Aas (aas@bergen.sn.no)
Sun, 24 Nov 1996 11:07:11 +0100


In message <9611240612.AA88825@panther.middlebury.edu>, Otis Gospodnetic writes:
> I noticed that when I try checking if my script already visited a certain web
> server I need to do a check like this:
> 
> if ($ua->no_visits($u->host) <= 2) {
> 	# first visit, even though $ua->no_visits($u->host) actually gives
> 	# me 2, and not 1.   I guess that is because I use RobotUA, and not
> 	# plain UserAgent (robots.txt is then first visit)

That is true, but a plain UserAgent does not have the no_visits()
method either.

> }
> else {
> 	# seen $u->host before
> }
> 
> The problem is that checking $ua->no_visits() against 2 is not good enough
> since sometimes $ua->no_visits() gives me 3 when I access a server for the
> first time.  For example, try using RobotUA and fetching http://www.w3.org/
> $ua->no_visits() will give 3 for the first visit.

I guess this means that the first visit was "robots.txt", then the 
second visit gave you a "redirect" and the third visit was the HTML 
index page.

> Is there any way I can accurately check if my script has visited a certain web
> server before or not using libwww-perl methods ?

I suggest that you test before you call $ua->request if that is possible:

  $first_visit = ($ua->no_visits($u->host) == 0);

  $ua->request($req);

  if ($first_visit) {
    #....
  } else {
    #...
  }

Regards,
Gisle