title: using python to log into booking.com
body: <p>I am trying to log in to <code>booking.com</code> to download my rental income data. The form has the html tag:</p>
  
  <pre><code>&lt;form class="nw-signin" novalidate=""&gt;
  </code></pre>
  
  <p>Python code:</p>
  
  <pre><code>import mechanize
  from bs4 import BeautifulSoup
  import urllib2 
  import cookielib
  
  cj = cookielib.CookieJar()
  br = mechanize.Browser()
  br.set_handle_robots(False)
  br.set_cookiejar(cj)
  br.open("https://account.booking.com/")
  
  formcount=0
  for frm in br.forms():  
    if str(frm.attrs["class"])=="nw-signin":
      break
    formcount=formcount+1
  br.select_form(nr=formcount)
  br.form['username'] = '1272897'
  br.submit()
  
  print br.response().read()
  </code></pre>
  
  <p>but I get the error:</p>
  
  <pre><code>FormNotFoundError                         Traceback (most recent call last)
  &lt;ipython-input-3-ee31ffcb0057&gt; in &lt;module&gt;()
       15     break
       16   formcount=formcount+1
  ---&gt; 17 br.select_form(nr=formcount)
       18 br.form['username'] = '1272897'
       19 br.submit()
  
  C:\Users\kerss\Anaconda2\lib\site-packages\mechanize\_mechanize.pyc in select_form(self, name, predicate, nr, **attrs)
      666                     description.append('%s = %r' % (k, v))
      667             description = ", ".join(description)
  --&gt; 668             raise FormNotFoundError("no form matching " + description)
      669 
      670     def click(self, *args, **kwds):
  
  FormNotFoundError: no form matching nr 0
  </code></pre>
  
  <p>I'm scratching my head a lot here! Can anyone see where I'm going wrong?</p>
  
  <p>If I run</p>
  
  <pre><code>import mechanize
  from bs4 import BeautifulSoup
  import urllib2 
  import cookielib
  
  count = 0
  cj = cookielib.CookieJar()
  br = mechanize.Browser()
  br.set_handle_robots(False)
  br.set_cookiejar(cj)
  br.open("https://account.booking.com/")
  for form in br.forms():
      count = count +1
      print count
  </code></pre>
  
  <p>nothing gets printed, indicating that </p>
  
  <pre><code>for form in br.forms():
  </code></pre>
  
  <p>is never true, so there are no forms on the page, but there cleary is a form on the page!</p>