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

I'm using WWW::Mechanize to enter data into a web page. How can I find out the name of the for and the name of the buttons? Any help would be appreciated, thanks. Here is the (slightly modidified to protect the site) HTML.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-12 +52"> <meta http-equiv="Content-Language" content="en-us"> <title>The Submission Form</title> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <base href="http://www.somewebsite.com/subdir/post.htm"><meta name="Mi +crosoft Theme" content="safari-color-change 100, default"></head> <body bgcolor="#000000" text="#CCCC99" link="#FFFF00" vlink="#FF0000" +alink="#FFFFFF"><!--mstheme--><font face="trebuchet ms, arial, helvet +ica"> <p> </p> <h1><!--mstheme--><font color="#CCCC66">The Place<!--mstheme--></font> +</h1> <p> [ <a href="index.htm" target="_top">Contents</a> | <a href="post.htm" target="_top">Post</a> ] </p> <!--msthemeseparator--><p align="center"><img src="_themes/safari-colo +r-change/safsepd.gif" width="600" height="10"></p> <h3><!--mstheme--><font color="#CC6600"><tt>POST ARTICLE</tt><!--msthe +me--></font></h3> <form method="POST" action="_vti_bin/shtml.exe/post.htm?68" webbot-act +ion="--WEBBOT-SELF--"> <input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"> <p> <strong>Subject:</strong><br> <input type="TEXT" name="Subject" size="50" value="Re: test2"> <br +> <strong>Comments:</strong><br> <textarea name="Comments" rows="6" cols="50"></textarea> <br> <br> <input type="SUBMIT" value="Post Article"> <input type="RESET" val +ue="Reset Form"> </p> </form> <!--msthemeseparator--><p align="center"><img src="_themes/safari-colo +r-change/safsepd.gif" width="600" height="10"></p> <h5><!--mstheme--><font color="#CC9933">Last changed: October 08, 2003 <!--mstheme--></font></body> </html>

Replies are listed 'Best First'.
Re: WWW::Mechanize & HTML
by jasonk (Parson) on Oct 08, 2003 at 13:31 UTC

    You can find the name by looking for the name="something" tag in the form or input tags, but as you have discovered, there is no requirement for them to be named at all, the form you have here doesn't have a name. WWW::Mechanize also lets you select forms by number, rather than name, so you can use $agent->form_number(1) to select the form you want to work with, and can just use $agent->submit() to submit the form, and just ignore the buttons altogether.


    We're not surrounded, we're in a target-rich environment!
      Great! Thank you very much. I was trying to use click('button_name') or just click() it wasn't working. I'll try submit().

      Also, I tried using the readmore tag followed by code then my code block followed by a /code tag and then a /readmore (with <> around them of course) and the readmore didn't work. Do youo know what I did wrong? Thanks again.

      click() and submit() failed and now I know why. I used response() to get the following error message.
      <HEAD><TITLE>An Error Occurred</TITLE></HEAD> <BODY> <H1>An Error Occurred</H1> 401 Authorization Required </BODY> </HTML>
      When I get() the form I do it like this.
      get("http://name:password\@www.site.com/page.htm")
      So I should already be authorized right? I'm not sure what I'm doing wrong. Any ideas?
        Actually the get looks like this
        get("http://name:pwd\@www.site.com/subdir/_vti_bin/shtml.exe/post.htm? +106");