title: Python Mechanize - Login
body: <p>I am trying to login to a website and get data from it. I can't seem to get mechanize to work on the following site. I have provided the HTML below. Could someone please give me brief help of how I can log in and print the next page?</p>
  
  <p>I have tried using mechanize and looping through br.forms(). I can see the form in that but I am having problems getting my username and password insert in and then hitting submit.</p>
  
  <pre><code>&lt;div class="loginform" id="loginpage" style="width: 300px;"&gt;
  &lt;div class="loginformentries" style="overflow: hidden;"&gt;
  &lt;div class="clearfix"&gt;
  &lt;div class="loginformtitle"&gt;Sign-in to your account&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="clearfix"&gt;
  &lt;div class="loginformlabel"&gt;&lt;label for="USERID"&gt;Username:&lt;/label&gt;&lt;/div&gt;
  &lt;div class="loginforminput"&gt;&lt;input name="USERID" id="USERID" style="width: 150px;" type="text" value=""&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="clearfix"&gt;
  &lt;div class="loginformlabel"&gt;&lt;label for="PASSWDTXT"&gt;Password:&lt;/label&gt;&lt;/div&gt;
  &lt;div class="loginforminput"&gt;&lt;input name="PASSWDTXT" id="PASSWDTXT" style="width: 150px;" type="password" value=""&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="clearfix"&gt;
  &lt;div class="loginformlabel"&gt;&lt;label for="usertype"&gt;Select Role:&lt;/label&gt;&lt;/div&gt;
  &lt;div class="loginforminput"&gt;&lt;select name="usertype" id="usertype" style="width: 150px;"&gt;&lt;option value="participant"&gt;Participant&lt;/option&gt;
  &lt;option value="sponsor"&gt;Sponsor&lt;/option&gt;&lt;/select&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="loginformsubmit" style="text-align: right;"&gt;&lt;span class="button"&gt;&lt;button class="buttoninsidebuttonclass" type="submit"&gt;Login&lt;/button&gt;&lt;/span&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="loginformdescription"&gt;Both entries are case sensitive. If you fail to login &lt;strong&gt;five&lt;/strong&gt; consecutive times your account could be disabled.&lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I am trying something like this...</p>
  
  <pre><code>import mechanize
  
  br = mechanize.Browser()
  
  br.open("test")
  
  br.select_form(name="loginform")
  br["USERID"] = 'xxxxx'
  br["PASSWDTXT"] = 'xxxxx'
  br.submit()
  print br.title()
  </code></pre>
  
  <p>But I don't know how to verify that I am on the next page</p>