How to print Radio Control information
I am using mechanize
module to retrieve information from a web page. It has a radio control section which I select before moving to the next page. I could easily select the value by assigning value to it. But coulnt retrieve the value of the candidate radio button. RadioSelect
part of my form looks like below:
<RadioControl(rdoSelect=[1634,ABX EXPRESS, 16650,XYZ EXP])>
I could easily set the values by:
br.form['txtSou开发者_运维知识库rce']='1634,ABX EXPRESS'
What I want is to retireve the list :
[1634,ABX EXPRESS, 16650,XYZ EXP]
UPDATE:
When I gave
print br.form['rdoSelect']
It gives [] as result
I could get the value using
print br.form.possible_items("rdoSelect")
But its giving me this
/usr/lib/python2.5/site-packages/ClientForm.py:2984: DeprecationWarning: [item.name for item in self.items]
return c.possible_items(by_label)
Instead of:
print br.form.possible_items("rdoSelect")
mechanize says to use:
options = [item.name for item in form.find_control('rdoSelect').items]
Example use:
#!/usr/bin/python
import re
import mechanize
br = mechanize.Browser()
r = br.open("http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_RADIO.html")
form = mechanize.ParseResponse(r, backwards_compat=False)[2]
options = [item.name for item in form.find_control('pizzasize').items]
print options
Yields:
['S', 'M', 'L']
First, a deprecation warning is not an error. Usually it means the library or code you are running was written for an earlier version of Python.
I am not sure how txtSource relates to rdoSelect (seems you expect them to contain the same value?). However a radio button usually has a symbolic value rather than the text displayed. Can you provide a sample of the HTML code?
精彩评论