hi...

writing a quick perl script to hit a site... i'm getting the same response,
which appears to be the base site, as opposed to the page i'm trying to
fetch/get...

i've simplified things, and am using 3 different approaches to get the
page.. with no luck...

i've tried using wget
=> wget -O fs.txt
http://apps3.oti.fsu.edu/RegistrarCourseLookup/SearchResults?requestType=PUB
LIC&courseNumber=&term=20041&department=2101Accounting&level=&location=0100F
SU+Main+Campus&specialProgram=-9999&beginningTime=&openSections=Y&endingTime
=&searchCriteria=-9999&criteriaDesc=

and i get the same page that i'm getting with my sample routines...

i'm running on linux rh8.0 with perl 5.8. my gut tells me if i can get wget
to work (or vice versa).. i'd be ok... it's got to be something simple that
i'm missing..

any idea/comments/criticisms would be helpful!!!!!

thanks

-bruce


sample code:
#############################################################
#!/usr/bin/perl -w

#use strict;

use HTML::TreeBuilder;
use LWP::UserAgent;
use URI::Escape;
use WWW::Mechanize;


# The following url/query is what is present in the
# browser address. as far as i can tell... i can simply type this
# into any browser i have on both linux/windows..
# and i get the correct page...
#
# each sub attempts to call/get the page using
# different approaches with no luck..
#

######################
#
http://apps3.oti.fsu.edu/RegistrarCourseLookup/SearchResults?requestType=PUB
LIC&courseNumber=&term=20041&department=2101Accounting&level=&location=0100F
SU+Main+Campus&specialProgram=-9999&beginningTime=&openSections=Y&endingTime
=&searchCriteria=-9999&criteriaDesc=
######################

   my $ua = new LWP::UserAgent;

   $ua->timeout(30);
   $ua->agent("Mozilla/4.0 (compatible; MSIE 4.01; Windows95)" .
$ua->agent);

   my $mech_url =
"http://apps3.oti.fsu.edu/RegistrarCourseLookup/SearchForm";;

   my $url = "http://apps3.oti.fsu.edu/RegistrarCourseLookup/SearchResults";;

   my $term = "20041";
   my $dept = "2101Accounting";

#
# comment out the two you don't want to try...
#

#  &mechanize($mech_url, $term, $dept); # use www::mechanize
#   &userAgent($url, $term, $dept);      # use ua->get(url, %query)
   &request($url, $term, $dept);       # use http::request

die;

sub mechanize
{
   my ($url, $term, $dept) = @_;

   my $agent = WWW::Mechanize->new();

   # Retrieve main page
   $agent->get($url);

   my $login = $agent->form_name('searchForm');
   if ( ! $login ) {
        warn "Nothing came back";
        exit;
   }

   $agent->field('requestType' => "PUBLIC");
   $agent->field('courseNumber' => "");
   $agent->field('term' => $term);
   $agent->field('department' => $dept);
   $agent->field('level' => "");
   $agent->field('location' => "0100FSU Main Campus");
   $agent->field('specialProgram' => "-9999");
   $agent->field('beginningTime' => "");
   $agent->field('openSections' => "Y");
   $agent->field('endingTime' => "");
   $agent->field('searchCriteria' => "-9999");
   $agent->field('criteriaDesc' => "");
   $agent->submit();

#   print $agent->content();

}


sub request
{

   my ($url, $term, $dept) = @_;

   my $ua = new LWP::UserAgent;
   $ua->timeout(30);
   $ua->agent("Mozilla/4.0 (compatible; MSIE 4.0; Windows95)" . $ua->agent);

   my $req = new HTTP::Request GET => $url;
   $req->content_type('application/x-www-form-urlencoded');

   my $cstr;

   $cstr = "?requestType=PUBLIC";
   $cstr = $cstr . "&courseNumber=";
   $cstr = $cstr . "&term=". uri_escape($term);
   $cstr = $cstr . "&department=". uri_escape($dept);
   $cstr = $cstr . "&level=";
   $cstr = $cstr . "&location=". uri_escape("0100FSU Main  Campus");
   $cstr = $cstr . "&specialProgram=-9999";
   $cstr = $cstr . "&beginningTime=";
   $cstr = $cstr . "&openSections=Y";
   $cstr = $cstr . "&endingTime=";
   $cstr = $cstr . "&searchCriteria=-9999";
   $cstr = $cstr . "&criteriaDesc=";


   $req->content($cstr);
   my $res = $ua->request($req);
   my $q1c = $res->content;
   print $q1c;

   print " url  $url  semt  $term, dept $dept\n";

   foreach (keys %{$res->headers()})
   {
      print "$_ = ", $res->headers()->{$_}, "\n";
   }

}

sub userAgent
{

   my ($url, $term, $dept) = @_;

   my $res;
   my $ua;
   my $req;

   my $agent;
   my %query;


   $query{requestType} = "PUBLIC";
   $query{courseNumber}= "";
   $query{term} = uri_escape($sem_url);
   $query{department} = uri_escape($dept_key);
   $query{level} = "";
   $query{location} = uri_escape("0100FSU Main Campus");
   $query{specialProgram} = "-9999";
   $query{beginningTime} = "";
   $query{openSections} = "Y";
   $query{endingTime} = "";
   $query{searchCriteria} = "-9999";
   $query{criteriaDesc} = "";


   $ua = new LWP::UserAgent;
   $ua->timeout(30);
   $ua->agent("Mozilla/4.0 (compatible; MSIE 4.0; Windows95)" . $ua->agent);

   #$req->content_type('application/x-www-form-urlencoded');

   #$ua->request($req);
   $res = $ua->get($url, \%query);
   my $q1c = $res->content;
   print $q1c;

   print " url  $url  semt  $term, dept $dept\n";


#          foreach (keys %{$req->headers()})
#          {
#              print "$_ = ", $req->headers()->{$_}, "\n";
#          }
#          print "agent->code = ". $req->code(). "\n";


die;
}

Reply via email to