【问题标题】:Checkbox input using python mechanize使用python mechanize的复选框输入
【发布时间】:2011-10-13 14:45:35
【问题描述】:

我想使用 python mechanize 填写表格。表格如下:

<POST https://10.20.254.39/cloud_computing/vmuser/migrate_vm/cli multipart/form-data
  <TextControl(vm=cli)>
  <TextControl(chost=10.20.14.39)>
  <SelectControl(dhost=[*, 28, 27])>
  <CheckboxControl(live=[on])>
  <CheckboxControl(undefinesource=[on])>
  <CheckboxControl(suspend=[on])>
  <SubmitControl(<None>=Submit) (readonly)>
  <HiddenControl(_formkey=85819e5a-02bb-42c8-891f-3ddac485438b) (readonly)>
  <HiddenControl(_formname=migrate_create) (readonly)>>

如何将 live 或 undefinesource(复选框)的值设置为 True(勾选)或 False(取消勾选) live 和 undefinsource 的项目是:

>>> print br.form.controls[4].get_items()
[<Item name='on' id='migrate_undefinesource' checked='checked' name='undefinesource' type='checkbox' id='migrate_undefinesource' value='on' class='boolean'>]
>>> print br.form.controls[3].get_items()
[<Item name='on' id='migrate_live' checked='checked' name='live' type='checkbox' id='migrate_live' value='on' class='boolean'>]

【问题讨论】:

    标签: python checkbox mechanize


    【解决方案1】:

    我做到的一种方法是

    br.find_control("live").items[0].selected=True
    

    【讨论】:

      猜你喜欢
      • 2011-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 2022-11-29
      • 2014-12-12
      • 2022-01-08
      • 1970-01-01
      相关资源
      最近更新 更多