How do you select choices that is not inside a form using Python? -


i'd know how select option menu not inside form using mechanize? page i'm getting data, has selection option inside div , not on form

<select name="name" onchange="somejavascript;">     <option value="-1">value -1</option>     <option value="1">value 1</option>     <option value="2">value 2</option> </select> 

# don't have page source. hope helps. html = """<select name="name" onchange="somejavascript;">     <option value="-1">value -1</option>     <option value="1">value 1</option>     <option value="2">value 2</option> </select>"""  # work on string above forms  = mechanize.parsestring(html, 'fake')  # there 1 form here, form htmlform instance form = forms[0]  control = form.controls[0] # select  # values control 'name' print [item.attrs['value'] item in control.items]   # ['-1','1','2']  # current value control print form['name']   # ['-1']  # select choice (e.g. choice value '2') form['name'] = ['2']  # verify value print form['name']   # ['2'] 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -