如何使用多机械化python选择单选按钮

时间:2014-04-01 21:41:31

标签: python automation mechanize mechanize-python

我有一个简单的PHP表单,我想使用multimechanize选择单选按钮,我可以选择填充文本字段,但我不知道如何使用单选按钮或复选框... < / p>

我尝试了以下但不起作用

    # select first (zero-based) form on page
    br.select_form(nr=0)
    # set form field
    br.form['name'] = 'foo'
    br.form['email'] = 'foo@foo.com'
    br.form['gender'] = 'male'

<form method="post" action="/mechanize/index.php">
   Name: <input type="text" name="name" value="">
   <span class="error">* </span>
   <br><br>
   E-mail: <input type="text" name="email" value="">
   <span class="error">* </span>
   <br><br>
   Website: <input type="text" name="website" value="">
   <span class="error"></span>
   <br><br>
   Comment: <textarea name="comment" rows="5" cols="40"></textarea>
   <br><br>
   Gender:
   <input type="radio" name="gender"   value="female">Female
   <input type="radio" name="gender"   value="male">Male
   <span class="error">* </span>
   <br><br>
   <input type="submit" name="submit" value="Submit">
</form>

2 个答案:

答案 0 :(得分:0)

br.form.find_control(name="gender").value = 'male'
br.submit()

答案 1 :(得分:-1)

我用br.form['gender'] = ['female']

解决了这个问题