Differentiating Between Html Form Select Items With The Same Name
I'm trying to dynamically fill a form in Python using Mechanize. However, when I inspected the source of the HTML page that has the form, I realized that some of the controls on th
Solution 1:
You can use BeautifulSoup to parse the response to get the select options
import mechanize
from BeautifulSoup import BeautifulSoup
br = mechanize.Browser()
resp = br.open('your_url')
soup = BeautifulSoup(resp.get_data())
second_select = soup.findAll('select', name="mv_searchspec")[1]
# now use BeautifulSoup API to get the data you want
You can't do something like br['mv_searchspec'] = 'foo'
as obviously this is ambigious. You should be able to do this though
br.select_form(nr=0) # select index
controls = br.form.controls
controls[desired_index]._value = 'your_value'
...
br.submit()
Post a Comment for "Differentiating Between Html Form Select Items With The Same Name"