开发者

What is the best way to get the values of a radio button set with lxml?

For example I have the following radio buttons:

<input type="radio" name="hand"  id='hand_left' checked value="L"> 
  <label for='hand_left'>Left</label>

<input type="radio" name="hand" id='hand_right' value="R"> 
  <label for='hand_right'>Right</label>

And have the following parsing code:

import lxml.html as lh

doc=lh.parse(response) # response is the response of 
                       # http post that returns the above html

for el in doc.iter('input'):
   if el.name == 'hand':
     print el

That prints out two InputElements, but lxml only returns a value for the开发者_开发技巧 checked one and returns None for the unchecked one (as per the lxml docs). I'd like to get each of the potential values regardless of which one is checked.

<InputElement 8715f8c name='hand' type='radio'>
<InputElement 8715f8f name='hand' type='radio'>


You could use el.attrib['value'] instead of el.value

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜