randy...

here's the rewritten app...



#############################################################
#
# uminnesota.pl. test perl app to extract/parse class
#       schedule from the onestop2.umn.edu registrar site...
#
#
# todo.. need to create the getinfo routine to parse the
#        class information, and write it out
#
#############################################################
#!/usr/bin/perl -w

use strict;

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

   my $ua = new LWP::UserAgent;

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

#
# get the top level university class site
#
  my $base_url =
"http://onestop2.umn.edu/courseinfo/classschedule_selectsubject.jsp?institut
ion=UMNTC";

  my $base_search_url =
"http://onestop2.umn.edu/courseinfo/viewClassScheduleTermAndSubject.do";;


# get semesters
my (%s1) = &getsemesters($base_url);

# get depts
my (%d1) = &getdepts($base_url);


       &g1($base_search_url, \%s1, \%d1);

print "we're here...\n";
die;



#################################
#
#
#################################
sub getsemesters
{
   my ($url0) = @_;
   my (%sem_);

   my $req = new HTTP::Request GET => $url0;

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

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

   my $_tree = HTML::TreeBuilder->new_from_content($res->content); # tree

   # get the specific select
   my @_sel = $_tree->look_down("_tag"=>"select", "name"=>"searchTerm");

   #get the option/semester list
   my @_option = $_sel[0]->look_down("_tag"=>"option");
   foreach $a (@_option)
   {
      $sem_{$a->attr('value')} = $a->as_text();
  }

   return(%sem_);
}


#
# return the hash containing the dept list
#
#   if necessary, might need to also provide the
#   short name for the dept..
#
sub getdepts
{
   my ($url) = @_;
   my (%depts_);

   my $req = new HTTP::Request GET => $url;

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

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

   my $_tree = HTML::TreeBuilder->new_from_content($res->content); # tree

   # get the specific select
   my @_sel = $_tree->look_down("_tag"=>"select", "name"=>"searchSubject");

   #get the option/semester list
   my @_option = $_sel[0]->look_down("_tag"=>"option");
   foreach $a (@_option)
   {
      $depts_{$a->attr('value')} = $a->as_text();
   }

   return(%depts_);
}

sub g1
{
  my ($url, %semester, %dept);
  my ($u, $s, $d);
  ($u, $s, $d)  = @_;

   $url = $u;
   %semester = %$s;
   %dept = %$d;


my $institution = "?institution=UMNTC";
my $searchterm = "&searchTerm=";
my $searchsubject = "&searchSubject=";
my $q_string = "&searchFullYearEnrollmentOnly=false&Submit=View";

my $semester_key;
my $dept_key;

my $url1;
my $res1;
my $ua;
my $req_;

foreach $semester_key (keys(%semester))
{
     foreach $dept_key (keys(%dept))
     {
       print " sem_key = $semester_key   deptkey  $dept_key\n";

       $url1 = $url;
       $url1 = $url1 . $institution;
       $url1 = $url1 . $searchterm. uri_escape($semester_key);
#       $url1 = $url1 . $searchterm. $semester_key;
       $url1 = $url1 . $searchsubject. uri_escape($dept_key);
       $url1 = $url1 . $q_string;
  print "here  $url1 \n";

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

       $req_ = new HTTP::Request GET => $url1;

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

       $res1 = $ua->request($req_);

     }
}

die;

   my $q1c = $res1->content;
   #print $q1c;
print "url = $url1\n";

}

-bruce


-----Original Message-----
From: Randy W. Sims [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 5:29 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: an issue/error/problem...


[Please respond to list so others can help & be helped.]

On 6/17/2004 8:07 PM, bruce wrote:

> i did.... (just didn't have it in when i posted...) didn't make any
> difference...
>
> i also rearranged the app.. to pass the hash arrays into the child
> sub/function... no diff...
>
> but thanks..

I guess my point was that your description doesn't match the code: There
is no get1 function. There is a $res1 variable that isn't used. etc. Can
you reduce the problem to the smallest possible fully working example?
I.e. copy your file and start trimming until the problem goes away or
you can't trim it any more, but make sure it is still compilable.

Regards,
Randy.


Reply via email to