Python Mechanize select a form with no name

Mantas Vidutis picture Mantas Vidutis · Apr 6, 2010 · Viewed 23.9k times · Source

I am attempting to have mechanize select a form from a page, but the form in question has no "name" attribute in the html. What should I do? when I try to use

br.select_form(name = "")

I get errors that no form is declared with that name, and the function requires a name input. There is only one form on the page, is there some other way I can select that form?

Answer

YOU picture YOU · Apr 6, 2010

Try:

br.select_form(nr=0)

to select the first form

In Mechanize source,

def select_form(self, name=None, predicate=None, <b>nr=None</b>):
    """
    ...
    nr, if supplied, is the sequence number of the form (where 0 is the
    first).
    """