James,
You can use Mechanize for this sort of things:
http://github.com/tenderlove/mechanize/tree/master
Cheers, Sazima