JPC
JPC

Reputation: 8276

python and mechanize - seeing the options in a select field

My html form looks like this:

<form name="someform">
     <select name="someid">
          <option value ="option1">

I'm trying to see all of the choices and be able to choose them.

I can select the form like this:

br.select_form("someform")

I can print(br) and see the SelectControl that I want. If I do:

print br["someid"]

that's just a list but only contains the first value. Is there an API for HTMLForm that I can look at?

Upvotes: 3

Views: 2099

Answers (2)

ilprincipe
ilprincipe

Reputation: 866

Using br.possible_items("someid") gives you the list of options.

Upvotes: 3

inspectorG4dget
inspectorG4dget

Reputation: 113905

I think what you want to do is to print br.form. This prints out ONLY the options in the form. Also, if anything in the form is a dropdown, then the options for that dropdown should also show up.

You could then use BeautifulSoup to parse the options.

Hope this helps

Upvotes: 1

Related Questions