Post radiobuttons (forms) using lwp-useragent

Discussion in 'Perl Misc' started by Rubel Kanubel, Oct 12, 2003.

  1. Hi!

    I've created a script that automatically logs into a site and fills
    out a form. I'm using the LWP::Useragent module. The first form (the
    login form) is no problem getting through. Examplified by the
    following:

    <code>

    my $req = POST 'http://www.acme.com/login.php', [ name => 'john', pass
    => 'password' ];
    my $res = $ua->request($req);

    </code>

    here the "name" and "pass" parameters represents textfield form
    elements. The second form I'm trying to send includes radio button
    form elements. But it doesnt seem like I can pass parameters like
    above for these elements.

    The radio button name is "rad_query", and its possible values are
    "alt_1", "alt_2" and "alt_3".. but the following does not work

    <code>

    my $req = POST 'http://www.acme.com/login.php', [ rad_query" => 'alt
    1' ];
    my $res = $ua->request($req);

    </code>

    I know that radio buttons in php is represented as an array.. but I'm
    not sure if this is the same in perl.. so I have a problem: How do I
    pass radio button form elements by using LWP::Useragent.

    Any answers, comments, ideas etc. would be very much appreciated.
    Thanks!


    /Regards Rubel Kanubel
     
    Rubel Kanubel, Oct 12, 2003
    #1
    1. Advertising

  2. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    (Rubel Kanubel) wrote in
    news::

    > <code>
    >
    > my $req = POST 'http://www.acme.com/login.php', [ rad_query" => 'alt
    > 1' ];
    > my $res = $ua->request($req);


    I was about to point out that you wanted 'alt_1' but your code says either
    'alt 1' or "alt\n1", but then I noticed that the above code can't possibly
    work anyhow.

    Please post your real code by copy/paste instead of re-typing it.

    - --
    Eric
    $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    ts p , map $ _. $ " , qw e p h tona e and print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBP4mGYGPeouIeTNHoEQKcGQCg/VAijSzMYZ/6CY/ggRMXudo3BYYAoLNO
    bdLe5OTS6Rjm1fBqgMItn0Bo
    =RKMH
    -----END PGP SIGNATURE-----
     
    Eric J. Roode, Oct 12, 2003
    #2
    1. Advertising

  3. <tea_spoon>

    $req = POST 'http://www.acme.com/login.php', [ rad_query => 'alt_1' ];
    $res = $ua->request($req);

    </tea_spoon>


    Please point out exactly what you mean by "I was about to point out
    that you wanted 'alt_1'". FYI, this is just an example of the code
    that I'm executing to post form elements. The above two statements
    illustrates my attempt (that fails) to post a radio button form
    element. I'm sorry for the mis-spellings, but you should be able to
    make out for yourself the problem without getting picky about it. The
    question is: how can one post radio button form elements by using the
    LWP::Useragent module.



    Rubel

    "Eric J. Roode" <> wrote in message news:<Xns941282AC4B3C9sdn.comcast@206.127.4.25>...
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > (Rubel Kanubel) wrote in
    > news::
    >
    > > <code>
    > >
    > > my $req = POST 'http://www.acme.com/login.php', [ rad_query" => 'alt
    > > 1' ];
    > > my $res = $ua->request($req);

    >
    > I was about to point out that you wanted 'alt_1' but your code says either
    > 'alt 1' or "alt\n1", but then I noticed that the above code can't possibly
    > work anyhow.
    >
    > Please post your real code by copy/paste instead of re-typing it.
    >
    > - --
    > Eric
    > $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    > ts p , map $ _. $ " , qw e p h tona e and print
    >
    > -----BEGIN PGP SIGNATURE-----
    > Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
    >
    > iQA/AwUBP4mGYGPeouIeTNHoEQKcGQCg/VAijSzMYZ/6CY/ggRMXudo3BYYAoLNO
    > bdLe5OTS6Rjm1fBqgMItn0Bo
    > =RKMH
    > -----END PGP SIGNATURE-----
     
    Rubel Kanubel, Oct 12, 2003
    #3
  4. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    (Rubel Kanubel) wrote in
    news::

    > <tea_spoon>
    >
    > $req = POST 'http://www.acme.com/login.php', [ rad_query => 'alt_1' ];
    > $res = $ua->request($req);
    >
    > </tea_spoon>
    >
    >
    > Please point out exactly what you mean by "I was about to point out
    > that you wanted 'alt_1'".


    Sure. You said that the possible values of the radio button input were
    "alt_1", "alt_2", etc, but the code that you posted had: [ rad_query" =>
    'alt
    1' ]. Now, the first thing that occurred to me was that your program had
    a simple typo in it, and you had a mismatch between the value that the
    form required ("alt_1") and the value your program was supplying ("alt
    1").

    Then I saw that the line had a syntax error in it. That led me to
    believe that you had not copy/pasted the code, but instead had retyped
    it, and then all bets are off. If you mistyped the ", you could just as
    easily have mistyped the CGI value, and God knows what else. How can
    anyone help you debug your code if you don't post it, but instead post
    something that is *similar* to your code?


    > FYI, this is just an example of the code
    > that I'm executing to post form elements. The above two statements
    > illustrates my attempt (that fails) to post a radio button form
    > element.


    So even your re-posting above isn't the code that is the problem?

    > I'm sorry for the mis-spellings, but you should be able to
    > make out for yourself the problem without getting picky about it.


    I appreciate your confidence in my abilities, but debugging code that I
    can't see is not among my abilities.

    > The
    > question is: how can one post radio button form elements by using the
    > LWP::Useragent module.


    It looks like you're doing everything mostly correct. Obviously,
    something minor is amiss, and nobody here is going to find it unless you
    post a short but working program that illustrates the problem.

    - --
    Eric
    $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    ts p , map $ _. $ " , qw e p h tona e and print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBP4nd8GPeouIeTNHoEQIPPwCgnKT43JJVcAmbbw/qwcPqXYypDuYAoILF
    5BlE4I+LgizjSlFcmYCpWl9u
    =NVot
    -----END PGP SIGNATURE-----
     
    Eric J. Roode, Oct 13, 2003
    #4
  5. Rubel Kanubel <> wrote:

    > Please point out exactly what you mean by "I was about to point out
    > that you wanted 'alt_1'".



    Your problem specification said so, but your code did not say so.


    > I'm sorry for the mis-spellings, but you should be able to
    > make out for yourself the problem without getting picky about it.



    Computers are picky.

    It is likely their pickiness that is the cause of your problem.

    If you don't get picky about what instructions you are giving to
    the machine, then figuring out why the machine isn't doing what
    you want it to do will take a Really Long Time.


    There are thousands of people around the world reading what you
    write. It is common courtesy to take a bit of care to not lead
    them on a wild goose chase in code that does not even exist.


    > question is: how can one post radio button form elements by using the
    > LWP::Useragent module.



    Show us the code if you want us to debug the code.



    [ snip Text Over Full-quote Under ]

    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 13, 2003
    #5
  6. Rubel Kanubel

    Anno Siegel Guest

    Rubel Kanubel <> wrote in comp.lang.perl.misc:
    > <tea_spoon>
    >
    > $req = POST 'http://www.acme.com/login.php', [ rad_query => 'alt_1' ];
    > $res = $ua->request($req);
    >
    > </tea_spoon>
    >
    >
    > Please point out exactly what you mean by "I was about to point out
    > that you wanted 'alt_1'". FYI, this is just an example of the code
    > that I'm executing to post form elements. The above two statements
    > illustrates my attempt (that fails) to post a radio button form
    > element. I'm sorry for the mis-spellings, but you should be able to
    > make out for yourself the problem without getting picky about it.


    Picky? You are the one wanting help, so it's your job to present
    the problem in a comprehensible way. So long...

    Anno
     
    Anno Siegel, Oct 13, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. La Jesus
    Replies:
    9
    Views:
    1,353
    Gunnar Hjalmarsson
    Oct 27, 2003
  2. Gaurav

    Problem using LWP::UserAgent

    Gaurav, Oct 2, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    253
    Tad McClellan
    Oct 2, 2003
  3. Andrew
    Replies:
    1
    Views:
    414
    Gunnar Hjalmarsson
    Dec 5, 2003
  4. dan baker

    using LWP:UserAgent under htaccess

    dan baker, Jan 18, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    127
    dan baker
    Jan 18, 2004
  5. Zapanaz
    Replies:
    4
    Views:
    153
    Tad McClellan
    Oct 12, 2005
Loading...

Share This Page