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

I need to write a script that reads a text file (.csv) and import the information into a form. This form requires a username and password and cookies so I have no idea how to do this. Any ideas on where to get started? I'm trying to log into and perform searches on http://realquest.com/jsp/rq.jsp?action=switch&page=main.

Replies are listed 'Best First'.
Re: Filling out a form on password page
by neniro (Priest) on Mar 10, 2004 at 19:43 UTC
    Have a look at WWW::Mechanize. It can help you with the authentication/form part.

    An example for simple form-filling:

    #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $page = "http://www.heise.de/newsticker/"; $mech->get($page); $mech->form_number('2'); $mech->field('T' => 'SCO'); my $results = $mech->submit(); print $results->content(), "\n";
    best regards,
    neniro
      #!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $page = "https://www.realquest.com/jsp/rq.jsp?action=switch&page=ma +in"; $mech->get($page); $mech->form_number('1'); $mech->field('username' => 'test'); my $results = $mech->submit(); print $results->content(), "\n";
      I am getting the error: There is no numbered form 1 at login.pl. How can this be when the URL I am using has atleast one form?
        i have also different prolem. when i fill form like here: $mech->field('username' => 'test'); everythig goes ok, but when i fill it with some var: $mech->field('username' => $test); i should tell that var $test is passed as an sub arg. It tells me error: Died at /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1681. Any ideas? best gegards, rafael
Re: Filling out a form on password page
by blue_cowdawg (Monsignor) on Mar 10, 2004 at 18:38 UTC

    This seems straight forward enough to me. First off I would point you to CGI and suggest you read the man pages. In there are suggestions for how to deal with cookies and the like. Secondly talk to your system adminsitrator about file permissions and what user id your web server is running as and make sure your CSV file is working correctly.

    As far as reading in the CSV file there are more ways to do that than I can possibly enumerate here. The simplest of which would be:

    open FIN,"< myfile.csv" or die "could not open mysfile.csv:$!"; while(my $line=<FIN>){ chomp $line; my @fields=split/[\,]/,$line); # do something with it } # etc.

    Since you are trying to fill out a form with the data I would suggest you look at LWP::UserAgent and friends.

    What have you tried and what has failed and in what manner did it fail? You reference a web page, why?

    UPDATE: misunderstood the question(s).


    Peter L. Berghold -- Unix Professional
    Peter at Berghold dot Net
       Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.
Re: Filling out a form on password page
by EvdB (Deacon) on Mar 10, 2004 at 18:47 UTC
    I think the OP wants to drive a website from the outside. Go to http://search.cpan.org and search for likely words like 'WWW', 'CSV' or 'http' and then look to see what the modules you find can do for you.

    --tidiness is the memory loss of environmental mnemonics