http://www.perlmonks.org?node_id=821009

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

Dear Monks,

I am sure there is a simple command for this, but my google-fu is failing me. I would like to write a perl script that does a LWP request on a cgi page. To do so, I need the parameters, and sloshing through the HTML to figure out the parameters is hurting my head. Is there a simple command where I can feed a url to it, and it will spit out all the possible parameters that can be passed for the request?

Specifically I am looking to script this site:
http://www.bioinformatics.nl/cgi-bin/primer3plus/primer3plus.cgi

Getting the check boxes and input sequence.

Thanks in advance!

Here is the initial code, that posts the results on the page, but does not submit them:

Updated with failed code

Rather I should say that the result of this file, is the original webpage with the variables as given by the code, but the code does not press the "Pick Primers" button....

#!/usr/bin/perl use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->agent("Mozilla 8.0"); use HTTP::Request::Common qw(POST); my $req = (POST 'http://www.bioinformatics.nl/cgi-bin/primer3plus/prim +er3plus.cgi', ["SEQUENCE" => "AATGAGTTAATAGAATCTTTACAAATAAGAATATACACTTCTGCTTAGGATGAT +AATTGGAGGCAAGTGAATCCTGAGCGTGATTTGATAATGACCTAATAATGATGGGTTTTATTTCCAGAC +TTCACTTCTAATGGTGATTATGGGAGAACTGGAGCCTTCAGAGGGTAAAATTAAGCACAGTGGAAGAAT +TTCATTCTGTTCTCAGTTTTCCTGGATTATGCCTGGCACCATTAAAGAAAATATCATC[C]GGTGTTTC +CTATGATGAATATAGATACAGAAGCGTCATCAAAGCATGCCAACTAGAAGAGGTAAGAAACTATGTGAA +AACTTTTTGATTATGCATATGAACCCTTCACACTACCCAAATTATATATTTGGCTCCATATTCAATCGG +TTAGTCTACATATATTTATGTTTCCTCTATGGGTAAGCTACTGTGAATGGATCAATTAATAAAACACAT +GACCTATGCTTTAAGAAGCTTGCAAACACATGAAA", "SCRIPT_DETECTION_PICK_LEFT" => "checked", "SCRIPT_DETECTION_PICK_RIGHT" => "checked" ]); $request = $ua->request($req); $content = $request->content; open(OUTPUT,">output_here.html"); print OUTPUT "$content"; close(OUTPUT); exit;

Replies are listed 'Best First'.
Re: Getting all the parameters of CGI request
by trwww (Priest) on Feb 02, 2010 at 19:47 UTC

    Perhaps WWW::Mechanize::Shell is what you are looking for? For example after fetching the page the forms command lists all forms and fields:

    $ perl -MWWW::Mechanize::Shell -eshell (no url)>get http://www.bioinformatics.nl/.../primer3plus.cgi Retrieving http://www.bioinformatics.nl/.../primer3plus.cgi(200) http://www.bioinformatics.nl/.../primer3plus.cgi> forms Form [1] POST http://www.bioinformatics.nl/.../primer3plus.cgi (multipart/form-data) [mainForm] ... snip list of fields and default values where relevant ...
Re: Getting all the parameters of CGI request
by jettero (Monsignor) on Feb 02, 2010 at 19:25 UTC
    It may not list out the params, but it sure will help filling out the form: WWW::Mechanize. Most of the values will have defaults, so you'll only have to set one or two of them and you're done.

    -Paul

      It may not list out the params,

      Sure it does. $mech->forms gets you the forms, and $form->inputs gets you a form's inputs.

Re: Getting all the parameters of CGI request
by holli (Abbot) on Feb 03, 2010 at 11:38 UTC
    Get Firefox and the Firebug extension.


    holli

    You can lead your users to water, but alas, you cannot drown them.