Python Mechanize select value from <select> box

1k views Asked by At

I'm trying to use Mechanize to fill and submit a form, but I'm not able to fill select boxes, as it throws errors. How do I set value for select boxes before submitting it?

1

There are 1 answers

0
falsetru On BEST ANSWER

select a form, and set the value you want using item assignemnt browser[...] = [...].

b = mechanize.Browser()
b.open(url)
b.select_form(nr=0)
b['select_name_attribute'] = ['option_value']  # <-----
b.submit()