2012-12-31 21 views
0

我想填寫一個HTML表單,我正在使用python的mechanize模塊。 我的HTML代碼是這樣,對於複選框和下拉式是:啓用複選框只有ID

的複選框:form.find_control("cd_info").items[0].selected = True 的下拉列表:form['cdtype']= ['Error1']

錯誤:

<div id="post_cd"> 
<input role="checkbox" id="cd_info" class="cbox" type="checkbox"> 
<span class="s-iso" style="display:none"></div> 


<label for="type" id="cdtype" class="cd" style="width:60px;margin:1px;float:left;text-align:right;">CD type:</label> 
<select id='cdtype' class=" ui-iso" style="width:100px;margin:1px;float:left;"> 
       <option value="CD1">Error1</option> 
       <option value="CD2">Error1</option> 
       <option value="CD3">Error2</option> 
      </select> 

我有以下,但得到的錯誤嘗試

raise ControlNotFoundError("no control matching "+description) 
mechanize._form.ControlNotFoundError: no control matching name 'cd_info' 

    raise ControlNotFoundError("no control matching "+description) 
mechanize._form.ControlNotFoundError: no control matching name 'cdtype' 
+0

這個什麼建議嗎? –

回答

0

您的HTML代碼中沒有<form>。因此,在您撥打find_control或訂閱運營商時,可能form未指向您提供的HTML代碼周圍的元素。

你可以嘗試打印窗體的文本,以確保你正在尋找正確的事情:

print form