[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Job Snag-O (WWW::Mechanize)



My brother lives down in Kansas City. He's trying this whole substitute teacher thing. Every morning at 5:30am he has to wake up and check a website to see if there are any jobs available.

That sucks... Why not just have a robot page you awake if there ARE jobs available?

Isn't WWW::Mechanize da bomb? It took me 30 minutes to get this working:


$ cat jobs.pl
#!/usr/bin/perl

use WWW::Mechanize;

my $base_url = "https://secure.indep.k12.mo.us/webconnect";;
my $url1     = "$base_url/login/login.asp";
my $lastname = "********";
my $password = "********";
my $url2     = "$base_url/sub/SubAvailableJobs.ASP";

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

$mech->get( $url1 );
$mech->submit_form(
   form_name => 'frmLogin',
   fields    => { LastName  => $lastname, PinNumber => $password },
);
$mech->get( $url2 );
my $text = $mech->content;
$text =~ s/.*<table/<table/s;
$text =~ s/<.*?>/ /sg;

print $text;


So now, you can just run the program instead having to log into the website:

$ perl jobs.pl
6:06 AM Available Jobs 1/31/2007 No jobs available at this time.

So I threw that in cron to run every 15 minutes and email us...

*/15 4-7 * * * /usr/bin/perl /home/jhannah/brad/jobs.pl | mail -s "Job Snag-O" crapulence@yahoo.com,jay@jays.net

Now if only my brother had a pager I could wake him up if there was a job... :)

j


P.S.   Perl is the coolest.