Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Automatically fill out web forms from the command line

by MistaMuShu (Beadle)
on Dec 21, 2004 at 20:56 UTC ( [id://416616]=perlquestion: print w/replies, xml ) Need Help??

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

Hi all,

I'm helping out upload information about research publications. There is a jsp on the server which processes fields from a web interface into the database. Rather than input in each indivdual pub by cutting and pasting, I wanted to use a tab-delineated file of the pub information. I must be googling and searching for the wrong topic, because all I get are CGI tutorials. What would be a good way to fill out all the fields from the command-line and have it loop through my text file? Please forgive me for the simple question, and thank you for any hints or help.

Here's an abbreviated piece of the form. Very simple stuff

<form ACTION="addpub.jsp" METHOD="POST"><br /> <textarea rows="3" name="title" cols="75" WRAP></textarea><br /> <textarea rows="3" name="author" cols="75" WRAP></textarea><br /> ...

Replies are listed 'Best First'.
Re: Automatically fill out web forms from the command line
by kutsu (Priest) on Dec 21, 2004 at 21:03 UTC

    Have a look at WWW::Mechanize it should do what you want.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

      I just realized I can't get started because the first page is a Apache authenication/authorization page. I tried looking through Apache::Access for help, but I'm not sure this is the right track?

        I posted about this a few weeks ago and bart helped me to find the answer. Here's an example snippet of how to authenticate an htaccess system with WWW::Mechanize:

        use strict; use warnings; use WWW::Mechanize; my $agent = WWW::Mechanize->new( autocheck => 1 ); $agent->credentials( 'www.somesite.com:80', 'somerealm', 'user', 'password' ); $agent->get( 'http://www.somesite.com/index.html' ); print $agent->content();

        It's important to use the port number in the credentials URL. The realm is also important to get right. You can usually see it as the title of the dialog box that pops up in your browser when you visit an htaccess-restricted site.


        Dave

        If your set up through a proxy server you should be able to use $mech->proxy(['http'], 'http://user:pass@host:port/'); (port usually being 8080), which is documented in WWW::Mechanize POD. If not, I'm not sure and hopefully some other, wiser, monk will help you out.

        "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce

Re: Automatically fill out web forms from the command line
by Fletch (Bishop) on Dec 21, 2004 at 21:16 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://416616]
Approved by kutsu
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-06-12 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.