former form fields no longer found by mechanize python script
Question: 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.

My previous code that worked:

    
    
    # 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();
    

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:

    
    
    <form id="loginform" name="loginform" method="post" action="https://www.aesoponline.com/login.asp?x=x&amp;&amp;pswd=&amp;sso=">
    
      <input type="hidden" name="location" value="">
      <input type="hidden" name="qstring" value="">
      <input type="hidden" name="absr_ID" value="">
      <input type="hidden" name="foil" value="">
    
    
      <div style="margin: auto; text-align:center;">
        <div id="loginContainer" style="text-align: left;">
          <div id="loginContent">
            <div id="Div1" style="position:relative; left:65px;" class="hide-me-for-rebranding">
              <a href="http://www.frontlinetechnologies.com">
                <img src="images/frontlinelogo.png" border="0">
              </a>
            </div>
            <div id="loginLoginBox" style="position:relative;">
              <div id="loginAesopLogo" style="padding-bottom:0px;" class="hide-me-for-rebranding"></div>
              <!--endloginAesopLogo-->
              <div id="loginLoginFields" style="margin-top:0px;">
                <br>
    
                <table>
                  <tbody>
                    <tr height="25px">
                      <td width="30px"><span class="corrLoginFormText">ID:</span>
                      </td>
                      <td>
                        <input type="text" class="loginFormText" maxlength="80" id="txtLoginID" name="id" value="">
                      </td>
                    </tr>
                    <tr height="25px">
                      <td width="30px"><span class="corrLoginFormText">Pin:</span>
                      </td>
                      <td>
                        <input type="password" class="loginFormText" maxlength="20" id="txtPassword" name="pin">
                      </td>
                    </tr>
                  </tbody>
                </table>
    
                <table>
                  <tbody>
                    <tr height="30px">
                      <td width="75px" valign="top">
                        <a class="textButton" id="loginLink" name="loginLink" href="#"><span style="white-space:nowrap;">Login</span></a> 
                        <input type="hidden" id="submitLogin" name="submitLogin" value="1">
                      </td>
                      <td>
    
                        <div id="loginhelp" style="float:right;">
                          <img src="images/icon.pinreminder.png" alt="pin" width="10" height="15" align="top"><a href="forgot_pin.asp">Pin Reminder</a>
                          <br>
                          <img src="images/icon.loginproblems.png" alt="login" width="11" height="17" align="top"> <a href="http://help.frontlinek12.com/Employee/Docs/ClientServicesHelpGuide-LoginProblems.pdf">Login Problems</a>
                        </div>
    
                      </td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <!--endloginLoginFields-->
              <div id="errorLabel" style="position: absolute; top: 170px; left:5px;margin:0px;"><span class="assistanceText"></span>
              </div>
            </div>
            <!--endloginLoginBox-->
            <div id="loginContentText">
              <span class="loginContentHeader">Welcome To Absence Management</span>
              <br>
              <span class="loginContentText">
            				You are about to enter Frontline Absence Management!<br> 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.</span> 
              <br>
              <a class="textButton" href="http://www.frontlinek12.com/Products/Aesop.html"><span>Learn More</span></a>
    
            </div>
            <!--endloginContentText-->
    
          </div>
          <!--endLoginContent-->
          <div id="loginFooterShading" class="hide-me-for-rebranding">
            <div id="loginFooterLeft"></div>
            <div id="loginFooterRight"></div>
          </div>
          <!--endloginFooterShading-->
          <div id="loginFooter" style="text-align:center;width:725px;">
            <a href="http://www.frontlinetechnologies.com/Privacy_Policy.html" style="color: rgb(153, 0, 0) ; font-size:9px;" target="_blank">Privacy Policy</a>
            <br>© Frontline Technologies Group LLC &lt;
            <parm1>&gt;
              <br>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.
            </parm1>
          </div>
          <!--endloginReflections-->
        </div>
        <!--endLoginContainer-->
    
    
      </div>
      <!--end margin div -->
      <!-- MODAL DIALOG -->
      <div id="basicModalContent" style="display:none">
        <span class="assistanceText"></span>
      </div>
    </form>

Any assistance would be greatly appreciated. Thank you very much.


Answer: 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.

    
    
    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()
    

