Can't find matching form
Question: I am trying to use Python's mechanize module to submit a form value and
download a subsequent file. However, I keep getting an error saying the script
can't find the form.

The website I'm using is
[here](https://ccmis.dhs.state.ia.us/clientportal/providersearch.aspx).

I'm trying to select by County = 'Linn'.

Below is the script I have up to selecting the form...

    
    
    import mechanize
    
    url = 'https://ccmis.dhs.state.ia.us/clientportal/providersearch.aspx'
    
    br = mechanize.Browser()
    br.open(url)
    br.select_form(name="ctl00$MainContent$ddlSearchByLocationCounty")
    

I keep getting an error that there is no form with a matching name. When I use
developer tools this is the name of the that shows. Below is a snippet of the
HTML...

    
    
    <select name="ctl00$MainContent$ddlSearchByLocationCounty" id="ctl00_MainContent_ddlSearchByLocationCounty" style="width:150px;">
        <option value="">Select County</option>
        <option value="Adair">Adair</option>
        <option value="Adams">Adams</option>
        <option value="Allamakee">Allamakee</option>
    


Answer: You need to first select the form by name, ID, etc before you can select an
input and set its value. Here is the updated code which sets the country to
Linn. I recommend reviewing the cheat sheet at
<http://www.pythonforbeginners.com/cheatsheet/python-mechanize-cheat-sheet>.

    
    
    import mechanize
    
    url = 'https://ccmis.dhs.state.ia.us/clientportal/providersearch.aspx'
    
    br = mechanize.Browser()
    br.open(url)
    br.select_form(name="aspnetForm")
    
    country = br.form.find_control("ctl00$MainContent$ddlSearchByLocationCounty")
    country.value = ['Linn']
    print country.value
    

