chimni has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I have a question regarding sending data to a web form through a perl script and getting that data submitted automatically.
I have a reservation application that takes the fields
Name
Emp code
Deptt
and helps reserve rooms.
I have a wirless messenger application that enables me to send messages from my mobile and keeps a logfile of them.
What i want to do is send the above three fields from my mobile.
Parse that logfile for the data .
Then somehow do a http get of the web page enter the data and submit it.
Is there anyway i can do this?fill up a web form automatically and submit it?
thanks and regards
chimni

Replies are listed 'Best First'.
Re: Automating data entry to a web page
by Corion (Patriarch) on Jul 21, 2003 at 06:33 UTC

    Filling out a web form is very easy to do with WWW::Mechanize - it allows you to specify values for fields, almost like a real browser :

    use WWW::Mechanize; my $url = "http://your.messenger.com/" my $a = WWW::Mechanize->new(); $a->get($url); $a->follow_link( text_regex => qr/enter data/i ); $a->submit_form( form_number => 3, fields => { username => 'yourname', password => 'secret', message => 'hello world!', } );
    perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
Re: Automating data entry to a web page
by zentara (Cardinal) on Jul 21, 2003 at 14:20 UTC
    You probably can use LWP::UserAgent to post the formdata.
    use LWP::UserAgent; my $ua = LWP::UserAgent->new(timeout=>45); my $req = POST 'http://myhost.com/cgi-bin/script.pl', [id => '4301330018817403', total_amount => "$grand_total", location => 'hawaii', ]; my $content = $ua->request($req)->as_string;