#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $mech->get("http://some.site.on.our.intranet/jsp/indexPage.do"); $mech->submit_form( fields => { userName => 'myUserid', password => 'myPasswordYouDontNeedToKnow', } ); $mech->follow_link( text_regex => qr/Search for Employee/ ); $mech->submit_form( fields => { nom => 'myFirstName', prenom => 'myLastName', } ); $mech->follow_link( text_regex => qr/myFullName/ ); $mech->follow_link( text_regex => qr/Overview Badge Hours/ ); $mech->follow_link( n => 17 ); # link 17 is the previous month dump_hours(); $mech->follow_link( n => 18 ); # link 18 is the next month dump_hours(); $mech->follow_link( text_regex => qr/Logoff/ ); # the end sub dump_hours { my @links = $mech->find_all_links( text_regex => qr/\d+:\d+/ ); foreach my $link (@links) { my $total = $link->text(); # total hours worked $mech->get($link); my $text = $mech->content( format => 'text'); if ( $text =~ /(... \d\d\/\d\d\/\d\d\d\d) INOUT(.+)$/ ) { my $date = $1; my $hours = $2; print $date . " (" . $total . ") "; # $hours is a long string of hours, 5 positions wide while ($hours) { my $slice = substr($hours,0,5)."-".substr($hours,5,5); $hours .= "?"x5 if (length($hours) % 10 == 5); $hours = substr($hours,10); print $slice . " " ; } print "\n"; } } }