use WWW::Mechanize; use HTML::TokeParser; my $c_url = 'https://registrar.utm.utoronto.ca/student/timetable/new_tt_calprev.php?course='.$pre; my $url = 'https://registrar.utm.utoronto.ca/student/timetable/index.php'; my $mech = WWW::Mechanize->new(); my $stream = HTML::TokeParser->new(\$html); my $streamm = HTML::TokeParser->new(\$htmll); my $streammm = HTML::TokeParser->new(\$htmlll); my %dep; my %dep2; my @coursename; $mech->get($url); $html = $mech->content(); $stream->get_tag("option"); $term = 20095; # 20095 = Summer $year = 1 ;# 1st = 1 , 2nd = 2, 3rd = 3, 4th = 4 my @c_arr ;# Course array while(my $token = $stream->get_token()){ if($token->[2]{name} eq "dept[]"){ while(my $token = $stream->get_token("option")){ if($token->[1] eq "option"){ $c = $token->[2]{value}; $d = $stream->get_trimmed_text(); $dep{ $c } = $d; } } } } while (($key, $v) = each(%dep)){ #submit options to list course $coursecode = $key; $coursecode =~ s/\s//g; $mech->get($url); $mech->submit_form( fields=>{ session=>$term, 'yos[]'=>$year, 'dept[]'=>$key, }, ); $htmll = $mech->content(); while(my $tokenn = $streamm->get_token()){ #grab the prefixes from the listing so we can directly if($tokenn->[1] eq "a" && $tokenn->[2]{name}){ push(@coursename,$tokenn->[2]{name}); $c = $tokenn->[2]{name}; $dep2 { $key } = $c; } } #end while for prefix } while (($foo, $bar) = each(%dep2)) { print $foo; print $bar; }