title: WWW::Mechanize - Grab <form> action for variable to pass to $url2
body: <p>I've using WWW-Mechanize to login to a page for years, submit form data, then grab the data/display it etc. The problem is now the source site where I am grabbing from has started using another variable after the login (the POST data) which is a dynamic URL at random times (it's the user ID of the person I've logged in with, seems to be changing.) I can't seem to find a way to grab the action link to store it as a variable: $url2 </p>
  
  <pre><code>&lt;form name="searchForm" method="post" action="../Emsresponse/?id=106"  onsubmit="return validate()"&gt;
  </code></pre>
  
  <p>When I run my code, I store the original $url as well as $url2, which is a slightly different /real/ URL with variables at the, but it's becoming dynamic so I need to store the action part and in $url2 so I don't have to keep changing the static URLs variables. </p>
  
  <p>For example, this was working: </p>
  
  <pre><code>my $url = "www.whatever.com/form";
  my $url2 = "www.whatever.com/Ems/id?102";
  </code></pre>
  
  <p>I simply need to store the data within action (ie: ../Emsresponse/?id=106) as a variable, but I cannot find a reliable way to do this with Mechanize. </p>
  
  <p>So I need $url2 to contain the ?id=whatever-it-is-now so I don't have to keep modifying the code every 2 weeks.</p>
  
  <pre><code>$url  = "www.page.com";
  $url2 = "www.page.com/userName/id?=101";
  my $r = $mech-&gt;get($url2);
  
  #  if we are not logged in $r hold has a key previous holding the http response from the 302 redirect call to the login page
  if (1) {
  
      # if we were redirected to the login location we are not logged in
      if (1) {
          $mech-&gt;get($url);
          if ( $mech-&gt;success() ) {
              $mech-&gt;form_name("loginForm");
              $mech-&gt;set_fields( LoginUserName =&gt; ... );
              $mech-&gt;click();
              if ( $mech-&gt;success() ) {
                  $authme = 0;
              }
  
              # check for success --&gt; this is important to not break the script on any errors
              if (   $authme == 0
                  &amp;&amp; $mech-&gt;success() )
              {
                  $mech-&gt;cookie_jar-&gt;save($cookie_file);
  
                  $mech-&gt;form_name("searchForm");
                  $mech-&gt;set_fields( DateStart =&gt; $date_yesterday );
                  $mech-&gt;click();
                  if ( $mech-&gt;success() ) { }
  </code></pre>