title: Filling search form with mechanize
body: <p>I'm trying to make a search on a website using <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a> (first experience with this lib and i almost don't know html and browsing mechanics).</p>
  
  <p>It works okay for logging in a site, but than i fail to fill a search forms on next page.
  For logging in i use:</p>
  
  <pre><code>    from mechanize import Browser
      br = Browser()
      br.open(top_url)
      br.select_form(nr=0)
      br["login"] = username
      br["password"] = password
      br.submit()
  </code></pre>
  
  <p>Then i'd used loop on forms to see names of the form fields:</p>
  
  <pre><code>&gt;&gt;&gt; for i in br.forms():
  ...     print i
  ...     break
  ...
  </code></pre>
  
  <p>That gave me this:</p>
  
  <pre><code>&lt;naurp_form POST https://sd.priocom.com/fx/$sd/servlet.ru.naumen.sd.search.SearcherServlet multipart/form-data
    &lt;TextControl(sdsearch_ServiceCallIdSearchType=)&gt;
    &lt;SubmitControl(dosearchsdsearch_ServiceCallIdSearchType=&gt;) (readonly)&gt;
    &lt;HiddenControl(hidden_dosearchsdsearch_ServiceCallIdSearchType=) (readonly)&gt;
    &lt;TextControl(sdsearch_ServiceCallDescriptionSearchType=)&gt;
    &lt;SubmitControl(dosearchsdsearch_ServiceCallDescriptionSearchType=&gt;) (readonly)&gt;
    &lt;HiddenControl(hidden_dosearchsdsearch_ServiceCallDescriptionSearchType=) (readonly)&gt;
    &lt;HiddenControl(searchType__exists=1) (readonly)&gt;
    &lt;SelectControl(searchType=[ClientTitleSearchType, *ClientTitleSearchType, CrmLiteJuridicalClientContactPersonSearchType, CrmLiteByPhoneSearchType, ServiceTitleSearchType, ContractTitleSearchType, CrmLiteNaturalClientSearchType, CrmLiteJuridicalClientSearchType, SDTaskIdSearchType, SDTaskDescriptionSearchType, SDTaskIdSearchType, ServiceCallIdSearchType, ServiceCallCommentSearchType, CoreEmployeeSearchType, CoreOUSearchType, CoreEmployeeSearchType, CoreClientSearchType, CoreContractTitleSearchType, CoreServiceSearchType, KBaseSearchType, CMDBObjectTitleSearchType, CMDBObjectInvNumberSearchType])&gt;
    &lt;TextControl(searchString=)&gt;
    &lt;SubmitControl(doSearch=&gt;) (readonly)&gt;
    &lt;HiddenControl(hidden_doSearch=) (readonly)&gt;
    &lt;HiddenControl(searchUUID=) (readonly)&gt;
    &lt;CheckboxControl(searchInResult=[on])&gt;
    &lt;HiddenControl(searchInResult__exists=1) (readonly)&gt;
    &lt;HiddenControl(backURL=/fx/sd/ru.naumen.sd.published_jsp?uuid=coreboqme50d80000il15pbh3tiac13s) (readonly)&gt;
    &lt;SubmitControl(doClear=╨Ю╤З╨╕╤Б╤В╨╕╤В╤М ╤А╨╡╨╖╤Г╨╗╤М╤В╨░╤В╤Л) (readonly)&gt;
    &lt;HiddenControl(hidden_doClear=) (readonly)&gt;
    &lt;HiddenControl(__form_id=searchTab.searchForm) (readonly)&gt;
    &lt;HiddenControl(first_load=true) (readonly)&gt;&gt;
  </code></pre>
  
  <p>Total number of forms = 3 (0,1,2) what exactly matches web site.
  I'm interested in first form, <code>"sdsearch_ServiceCallIdSearchType"</code>.
  On actual website it looks like a field and a button ">>", obviously <code>dosearchsdsearch_ServiceCallIdSearchType</code></p>
  
  <p>So i'm trying this:</p>
  
  <pre><code>br.select_form(nr = 0)
  br['sdsearch_ServiceCallIdSearchType'] = '2770' 
  #also tried br.form['sdsearch_ServiceCallIdSearchType'] = '2770'
  response = br.submit("dosearchsdsearch_ServiceCallIdSearchType")
  tt_page = br.response().read()
  </code></pre>
  
  <p><strong>UPD</strong>:
  also tried with <code>.click()</code> method</p>
  
  <pre><code>response = br.click(type = 'submit',name = "dosearchsdsearch_ServiceCallIdSearchType")
  tt_page = br.response().read()
  </code></pre>
  
  <p>But in <code>tt_page</code> i still receive first search page (page where i'm trying to fill search form).</p>
  
  <p>Any tips appreciated.</p>
  
  <p>PS: Code of search form on website i need (I DON'T KNOW WHAT IT MEANS. I can guess but can't be sure my guess is true):</p>
  
  <pre><code>&lt;!--formbutton.jsp--&gt;
  &lt;tr id="sdsearch_ServiceCallIdSearchType_outer" &gt;
      &lt;th style="width:25%;"&gt;
          TT number
      &lt;/th&gt;
      &lt;td  align="left"
          style="width:100%;vertical-align:middle;"&gt;
          &lt;table border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td style="border:0px"&gt;
          &lt;input type="text"
                 id="sdsearch_ServiceCallIdSearchType"
                 name="sdsearch_ServiceCallIdSearchType"
                 size="30"
                 value=""
                 maxlength="254"               
                 style="" 
          /&gt;
          &lt;/td&gt;&lt;td style="border:0px"&gt;
  &lt;span id="dosearchsdsearch_ServiceCallIdSearchType_outer"
      name="dosearchsdsearch_ServiceCallIdSearchType_outer"
      &gt;&lt;input
          onclick="
                  mark_as_pressed(window.event, this);
                  "
          style="margin:1px;"    
      type="submit"
      id="dosearchsdsearch_ServiceCallIdSearchType"
      name="dosearchsdsearch_ServiceCallIdSearchType"
      value="&amp;#062;"
  /&gt;&lt;/span&gt;
  &lt;input type="hidden" id="hidden_dosearchsdsearch_ServiceCallIdSearchType" name="hidden_dosearchsdsearch_ServiceCallIdSearchType"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>PPS:
  <a href="http://stockrt.github.com/p/handling-html-forms-with-python-mechanize-and-BeautifulSoup/" rel="nofollow">This post was helpfull</a> and also some of posts on this site. But none gave me any tip why in my case it isn't working.</p>
  
  <p>Still can't find a way to fill that form and go to next page.</p>