title: Submitting nested form with python mechanize
body: <p>I am trying to submit a login form on a web page that looks something like this. I have also tried submit the nested form as well as submit both forms, same error every time.</p>
  
  <pre><code>&lt;form method="post" name="loginform"&gt;
       &lt;input type='hidden' name='login' value='1'&gt;
       &lt;form action="#" method="post" id="login"&gt;
            Username
            &lt;input type="text" name="username" id="username" /&gt;
            Password
            &lt;input type="password" name="password" id="password" /&gt;
            &lt;input type="submit" value='Login'  class="submit" /&gt;
  </code></pre>
  
  <p>here is my the python script I am using. I also noted that the forms aren't closed off with <code>&lt;/form&gt;</code> I am not sure if this has anything to do with my problem.</p>
  
  <pre><code>from mechanize import Browser
  
  br = Browser()
  
  br.set_handle_robots( False )
  br.addheaders = [('User-agent', 'Firefox')]
  
  br.open('http://www.example.com/')
  
  br.select_form(name="loginform")
  
  br['login'] = '1'
  br['username'] = 'user'
  br['password'] = 'pass'
  
  resp = br.submit()
  </code></pre>
  
  <p>the error I get is </p>
  
  <pre><code>ParseError: nested FORMs
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>import mechanize
  from BeautifulSoup import MinimalSoup 
  
  class PrettifyHandler(mechanize.BaseHandler):
      def http_response(self, request, response):
          if not hasattr(response, "seek"):
              response = mechanize.response_seek_wrapper(response)
          # only use BeautifulSoup if response is html
          if response.info().dict.has_key('content-type') and ('html' in response.info().dict['content-type']):
              soup = MinimalSoup (response.get_data())
              response.set_data(soup.prettify())
          return response
  
  br = mechanize.Browser()
  br.add_handler(PrettifyHandler())
  
  br.open('http://example.com/')
  
  br.select_form(nr=1)
  br.form['username'] = 'mrsmith'
  br.form['password'] = '123abc'
  resp = br.submit()
  
  print resp.read()
  </code></pre>