If you run the following program:
import mechanize
br = mechanize.Browser()
br.open("http://hansardindex.ontla.on.ca/hansarde.asp")
for f in br.forms():
print f.name
Only one line of output is printed. However if you visit the page there are many forms with names such as "DateFrom". Why does mechanize not list the other forms?
There is a difference between 'Forms' and 'Input'. A form can contain many input fields.
see http://www.w3schools.com/html/html_forms.asp
Mechanize is right there is only ONE form but with multiple input fields.
What you probably want to do is access the input fields by name. So for example setting the 'searchcontents' input field works like this:
form = forms[0]
form["searchcontents"] = "keyword"
for more information, please have a look at the mechanize documentation at http://wwwsearch.sourceforge.net/mechanize/forms.html
精彩评论