#!/usr/bin/perl

# randyahoo.pl
#
# a program to pull out URLs from Yahoo's random link finder
# at http://random.yahoo.com/bin/ryl
#
# recommend you use perl 5.003 or above and libwww-perl 5

# Virginia Knight, ILRT 
# 20 November, 2000

# this is hacked from the ROADS link checker bin/lc.pl
# (Author: Martin Hamilton <martinh@gnu.org>)
# probably there are still redundant bits in it
#
# For extracting information from headers of docs returned see HTTP::Response
# Response.pm in http://www.linpro.no/lwp/libwww-perl/lib/HTTP/

require LWP::Protocol::http;
require LWP::UserAgent;
use Getopt::Std;
use HTML::LinkExtor;
use Cwd;


$ua = new LWP::UserAgent;

open (OUTPUT,">randyahoo.out");


# I want 10 URLs back, please
$i=0;
until ($i>=10) {
 &check_url("http://random.yahoo.com/bin/ryl");
}


sub check_url {
  my($url) = @_;



  $request = new HTTP::Request 'HEAD', $url;
  $response = $ua->request($request);


# I'm only interested in working links
if ($response->code eq "200") {

# you can put further conditions here, e.g. restrict to a particular domain
#   if ($response->base =~ /\.fi\//) {
  print OUTPUT $response->base, "\n";
  $i++;
# }
}



}

close (OUTPUT);

exit;

