former form fields no longer found by mechanize python script
<p>Let me start by apologizing for my utter newbness. I was asked by a friend a couple years ago if I could write a program to automatically grab substitute teaching openings. It wasn't an area I knew anything about, but a couple tutorials allowed me to bang something out despite ignorance about html (and more than a little about Python for that matter). Script worked great since then but this year their site seems to have been redone and broke things, pushing it far beyond my understanding.</p>

<p>My previous code that worked:</p>

<pre><code># Create a Browser instance
b = mechanize.Browser()
# Load the page
b.open(loginURL)

# Select the form
b.select_form(nr=0)

# Fill out the form
b['id'] = 'XXXXXXXXXX'   # Note: I edited out my friend's login info here for privacy
b['pin'] = 'XXXX'

b.submit();
</code></pre>

<p>There is still only one form but the controls are now of type "hidden" and are not the ones I directly need any longer. I can see the old fields in the html when I examine it with developer mode and the names are the same but I can't figure out (tried some things that didn't work) how I would access them now. Here is the html:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form id="loginform" name="loginform" method="post" action="https://www.aesoponline.com/login.asp?x=x&amp;amp;&amp;amp;pswd=&amp;amp;sso="&gt;

  &lt;input type="hidden" name="location" value=""&gt;
  &lt;input type="hidden" name="qstring" value=""&gt;
  &lt;input type="hidden" name="absr_ID" value=""&gt;
  &lt;input type="hidden" name="foil" value=""&gt;


  &lt;div style="margin: auto; text-align:center;"&gt;
    &lt;div id="loginContainer" style="text-align: left;"&gt;
      &lt;div id="loginContent"&gt;
        &lt;div id="Div1" style="position:relative; left:65px;" class="hide-me-for-rebranding"&gt;
          &lt;a href="http://www.frontlinetechnologies.com"&gt;
            &lt;img src="images/frontlinelogo.png" border="0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div id="loginLoginBox" style="position:relative;"&gt;
          &lt;div id="loginAesopLogo" style="padding-bottom:0px;" class="hide-me-for-rebranding"&gt;&lt;/div&gt;
          &lt;!--endloginAesopLogo--&gt;
          &lt;div id="loginLoginFields" style="margin-top:0px;"&gt;
            &lt;br&gt;

            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr height="25px"&gt;
                  &lt;td width="30px"&gt;&lt;span class="corrLoginFormText"&gt;ID:&lt;/span&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;input type="text" class="loginFormText" maxlength="80" id="txtLoginID" name="id" value=""&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr height="25px"&gt;
                  &lt;td width="30px"&gt;&lt;span class="corrLoginFormText"&gt;Pin:&lt;/span&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                    &lt;input type="password" class="loginFormText" maxlength="20" id="txtPassword" name="pin"&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;

            &lt;table&gt;
              &lt;tbody&gt;
                &lt;tr height="30px"&gt;
                  &lt;td width="75px" valign="top"&gt;
                    &lt;a class="textButton" id="loginLink" name="loginLink" href="#"&gt;&lt;span style="white-space:nowrap;"&gt;Login&lt;/span&gt;&lt;/a&gt; 
                    &lt;input type="hidden" id="submitLogin" name="submitLogin" value="1"&gt;
                  &lt;/td&gt;
                  &lt;td&gt;

                    &lt;div id="loginhelp" style="float:right;"&gt;
                      &lt;img src="images/icon.pinreminder.png" alt="pin" width="10" height="15" align="top"&gt;&lt;a href="forgot_pin.asp"&gt;Pin Reminder&lt;/a&gt;
                      &lt;br&gt;
                      &lt;img src="images/icon.loginproblems.png" alt="login" width="11" height="17" align="top"&gt; &lt;a href="http://help.frontlinek12.com/Employee/Docs/ClientServicesHelpGuide-LoginProblems.pdf"&gt;Login Problems&lt;/a&gt;
                    &lt;/div&gt;

                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/tbody&gt;
            &lt;/table&gt;
          &lt;/div&gt;
          &lt;!--endloginLoginFields--&gt;
          &lt;div id="errorLabel" style="position: absolute; top: 170px; left:5px;margin:0px;"&gt;&lt;span class="assistanceText"&gt;&lt;/span&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;!--endloginLoginBox--&gt;
        &lt;div id="loginContentText"&gt;
          &lt;span class="loginContentHeader"&gt;Welcome To Absence Management&lt;/span&gt;
          &lt;br&gt;
          &lt;span class="loginContentText"&gt;
        				You are about to enter Frontline Absence Management!&lt;br&gt; Please enter your ID and PIN to login to your account, or click the button below to learn more about Frontline's growing impact on education.&lt;/span&gt; 
          &lt;br&gt;
          &lt;a class="textButton" href="http://www.frontlinek12.com/Products/Aesop.html"&gt;&lt;span&gt;Learn More&lt;/span&gt;&lt;/a&gt;

        &lt;/div&gt;
        &lt;!--endloginContentText--&gt;

      &lt;/div&gt;
      &lt;!--endLoginContent--&gt;
      &lt;div id="loginFooterShading" class="hide-me-for-rebranding"&gt;
        &lt;div id="loginFooterLeft"&gt;&lt;/div&gt;
        &lt;div id="loginFooterRight"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;!--endloginFooterShading--&gt;
      &lt;div id="loginFooter" style="text-align:center;width:725px;"&gt;
        &lt;a href="http://www.frontlinetechnologies.com/Privacy_Policy.html" style="color: rgb(153, 0, 0) ; font-size:9px;" target="_blank"&gt;Privacy Policy&lt;/a&gt;
        &lt;br&gt;Â© Frontline Technologies Group LLC &amp;lt;
        &lt;parm1&gt;&amp;gt;
          &lt;br&gt;All rights reserved. Protected under US Patents 6,334,133, 6,675,151, 7,430,519, 7,945,468 and 8,140,366 with additional patents pending.
        &lt;/parm1&gt;
      &lt;/div&gt;
      &lt;!--endloginReflections--&gt;
    &lt;/div&gt;
    &lt;!--endLoginContainer--&gt;


  &lt;/div&gt;
  &lt;!--end margin div --&gt;
  &lt;!-- MODAL DIALOG --&gt;
  &lt;div id="basicModalContent" style="display:none"&gt;
    &lt;span class="assistanceText"&gt;&lt;/span&gt;
  &lt;/div&gt;
&lt;/form&gt;</code></pre>
</div>
</div>
</p>

<p>Any assistance would be greatly appreciated. Thank you very much.</p>

<p>Try something like this if that html code is exactly what is on that page. When you put b.select_form(nr=0) there is the possibility that for some reason the first form is not what you are selecting. By looking for the form name in the b.select_form() you can ensure you find the correct form. Test it out and see if it works out. </p>

<pre><code>import mechanize
b = mechanize.Browser()
b.open(loginURL)
#since the actual form is named loginform just select it
b.select_form("loginform") 
b['id'] name of login input field
b['pin']
b.submit()
</code></pre>

python html forms mechanize hidden