Search code examples
pythonmechanize-python

Python Mechanize select value from <select> box


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?


Solution

  • 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()