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

This code is returning me the web form page. I want it to submit the web form and get the actual results page, not the form page. I'm not sure what I'm doing wrong.
use strict; use LWP::Simple; use URI::URL; my $url = url("http://genome.ucsc.edu/cgi-bin/hgGateway?clade=vertebra +te&org=0&db=0&hgsid=63734053"); $url->query_form(clade => "vertebrate", org => "Human", db => "hg17", position => "NM_000747", pix => 620, hgsid => 63734054, Submit => "submit", customTrackPage => "add your own custom tracks", hgTracksConfigPage => "configure tracks and display" ); my $page = get($url); open (OUTPUT, ">output.html") || die "Could not open output: $!\n\n"; print OUTPUT $page;

Replies are listed 'Best First'.
Re: web form submission help
by planetscape (Chancellor) on Nov 24, 2005 at 20:25 UTC

    If possible, I would suggest using WWW::Mechanize, which offers extensive examples and many articles for reference. Nodes using WWW::Mechanize abound here on PM; Super Search will undoubtedly turn up much helpful information.

    Also, helpful modules such as HTTP::Recorder and WWW::Mechanize::Shell exist to help you automate the creation of your WWW::Mechanize scripts.


    Update: For example, using HTTP::Recorder as described here produces the following snippet:

    $agent->get('http://genome.ucsc.edu/cgi-bin/hgGateway'); $agent->form_name('mainForm'); $agent->field('clade', 'vertebrate'); $agent->field('org', 'Human'); $agent->field('db', 'hg17'); $agent->field('pix', '620'); $agent->field('position', 'NM_000747'); $agent->click('Submit');

    And the "results" page looks something like this:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <SCRIPT LANGUAGE="JavaScript"> <!-- // start // find the top-level opener window var opwindow = window.opener; while (opwindow && opwindow.opener) { opwindow = opwindow.opener; } // update it with HTTP::Recorder's control panel if (opwindow) { opwindow.location = "http://http-recorder"; } // end --> </SCRIPT> <html> <head> <title> Human NM_000747 - UCSC Genome Browser v121</title> <meta http-equiv="Content-Script-Type" content="text/javascript"> <link rel="STYLESHEET" href="/style/HGStyle.css?rec-url=%252Fstyle%252 +FHGStyle.css&rec-action=norecord"> <base href="http://genome.ucsc.edu/cgi-bin/hgTracks?clade=vertebrate&o +rg=Human&db=hg17&position=NM_000747&pix=620&hgsid=63735965&Submit=sub +mit"> </head> <body background="../images/floret.jpg"> <h2> Known Genes</h2> <pre> <tt> <a href="hgTracks?position=chr17%3A7289129-7301656&hgsid=63735965&know +nGene=pack&hgFind.matches=NM_000747%2C&rec-url=hgTracks%253Fposition% +253Dchr17%253A7289129-7301656%2526hgsid%253D63735965%2526knownGene%25 +3Dpack%2526hgFind.matches%253DNM_000747%252C&rec-action=follow&rec-te +xt=NM_000747%2520at%2520chr17%253A7289129-7301656&rec-index=1"> NM_000747 at chr17:7289129-7301656</a> - (NM_000747) nicotinic acetylcholine receptor beta subunit </pre> </tt> <h2> RefSeq Genes</h2> <pre> <tt> <a href="hgTracks?position=chr17%3A7289129-7301656&hgsid=63735965&refG +ene=pack&hgFind.matches=NM_000747%2C&rec-url=hgTracks%253Fposition%25 +3Dchr17%253A7289129-7301656%2526hgsid%253D63735965%2526refGene%253Dpa +ck%2526hgFind.matches%253DNM_000747%252C&rec-action=follow&rec-text=C +HRNB1%2520at%2520chr17%253A7289129-7301656&rec-index=1"> CHRNB1 at chr17:7289129-7301656</a> - (NM_000747) nicotinic acetylcholine receptor beta subunit </pre> </tt> </body> </html>

    HTH,

    planetscape