title: Python Mechanize login form, sending input to a field with a randomly generated name
body: <p>I'm trying to automate the login to a site, <a href="http://www.tthfanfic.org/login.php" rel="nofollow">http://www.tthfanfic.org/login.php</a>.</p>
  
  <p>The problem I am having is that the password field has a name that is randomly generated, I have tried using it's label, type and id all of which remain static but to no avail.</p>
  
  <p>Here is the HTML of the form:</p>
  
  <pre><code>&lt;tr&gt;
      &lt;th&gt;&lt;label for="urealname"&gt;User Name&lt;/label&gt;&lt;/th&gt;
      &lt;td&gt;&lt;input type='text' id='urealname' name='urealname' value=''/&gt; NOTE: Your user name may not be the same as your pen name.&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;th&gt;&lt;label for="password"&gt;Password&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input type='password' id='password' name='e008565a17664e26ac8c0e13af71a6d2'/&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;th&gt;Remember Me&lt;/th&gt;&lt;td&gt;&lt;input type='checkbox' id='remember' name='remember'/&gt;
  &lt;label for="remember"&gt;Log me in automatically for two weeks on this computer using a cookie. &lt;/label&gt; Do not select this option if this is a public computer, or you have an evil sibling.&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td colspan='2' style="text-align:center"&gt;
          &lt;input type='submit' value='Login' name='loginsubmit'/&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>I've tried to format that for readability but it still looks bad, consider checking the code on the supplied page.</p>
  
  <p>Here is the code I get when printing the form through mechanize:</p>
  
  <pre><code>&lt;POST http://www.tthfanfic.org/login.php application/x-www-form-urlencoded
  
    &lt;HiddenControl(ctkn=a40e5ff08d51a874d0d7b59173bf3d483142d2dde56889d35dd6914de92f2f2a) (readonly)&gt;
  
    &lt;TextControl(urealname=)&gt;
  
    &lt;PasswordControl(986f996e16074151964c247608da4aa6=)&gt;
  
    &lt;CheckboxControl(remember=[on])&gt;
  
    &lt;SubmitControl(loginsubmit=Login) (readonly)&gt;&gt;
  </code></pre>
  
  <p>The number sequence in the PasswordControl is the part that changes each time I reload the page, in the HTML from the site it seems to have several other tags ascribed to it but none of them work when I try to select them, that or I'm doing it incorrectly.</p>
  
  <p>Here is the code I am using to try and select the control by label:</p>
  
  <pre><code>fieldTwo = br.form.find_control(label='password')
  
      br[fieldOne] = identifier
  
      br[fieldTwo] = password
  </code></pre>
  
  <p>I can post the rest of my login code if neccesary but this is the only part that is not working, I have had success with other sites where the password name remains the same.</p>
  
  <p>So, is it possible for me to select the passwordControl using it's label, type or ID, or do I need to scrape its name?</p>
  
  <p>EDIT: Oops, forgot to add the error message:</p>
  
  <pre><code>raise ControlNotFoundError("no control matching "+description)
  
  mechanize._form.ControlNotFoundError: no control matching label 'password'
  </code></pre>
  
  <p>SOLVED: </p>
  
  <p>Solution given by a guy on reddit, thanks Bliti.</p>
  
  <p>Working code:</p>
  
  <pre><code>br.select_form(nr=2)
  list = []
      for f in br.form.controls:           
          list.append(f.name)
      fieldTwo = list[2]
  </code></pre>