Javascript Python添加新控件会导致错误
我正在Python中使用mechanize。我无法设置SelectControl元素的值 我试图抓取的网页是Javascript Python添加新控件会导致错误,javascript,python,urllib2,mechanize,Javascript,Python,Urllib2,Mechanize,我正在Python中使用mechanize。我无法设置SelectControl元素的值 我试图抓取的网页是http://www.mcxindia.com/SitePages/indexhistory.aspx 我关心的部分源代码是: <tr> <td bgcolor="#f5f4f5" class="txtblue"><table border="0" align="center" cellpadding="
http://www.mcxindia.com/SitePages/indexhistory.aspx
我关心的部分源代码是:
<tr>
<td bgcolor="#f5f4f5" class="txtblue"><table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table id="mRbtLstSpotFut" border="0" style="font-weight:normal;height:85px;width:208px;">
<tr>
<td><input id="mRbtLstSpotFut_0" type="radio" name="mRbtLstSpotFut" value="1" checked="checked" /><label for="mRbtLstSpotFut_0">Commodity Future Indexes</label></td>
</tr><tr>
<td><input id="mRbtLstSpotFut_1" type="radio" name="mRbtLstSpotFut" value="0" onclick="javascript:setTimeout('__doPostBack(\'mRbtLstSpotFut$1\',\'\')', 0)" /><label for="mRbtLstSpotFut_1">Commodity Spot Indexes</label></td>
</tr><tr>
<td><input id="mRbtLstSpotFut_2" type="radio" name="mRbtLstSpotFut" value="2" onclick="javascript:setTimeout('__doPostBack(\'mRbtLstSpotFut$2\',\'\')', 0)" /><label for="mRbtLstSpotFut_2">Rainfall Indexes</label></td>
</tr>
</table></td>
<td> </td>
<td rowspan="3" valign="top"><p style="margin-top: 3px; margin-bottom: 0; margin-left: 0" align="justify">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="tablerowtxt1"> Selected Index</td>
<td> </td>
<td colspan="2"><select name="mDdlOtherIndex" id="mDdlOtherIndex" class="dd" style="width:170px;">
<option selected="selected" value="323">MCXCOMDEX</option>
<option value="324">MCXMETAL</option>
<option value="325">MCXENERGY</option>
<option value="326">MCXAGRI</option>
</select></td>
但我还想选择不存在的选项值“327”(因为单击单选按钮时JS会显示该值,mechanize无法处理该值)
因此,我尝试向窗体添加一个新控件,如
<option value="327">MCXENERGY</option>
但这给了我以下错误:
File "build\bdist.win-amd64\egg\mechanize\_form.py", line 2006
mechanize._form.ItemNotFoundError: insufficient items with name '327'
我哪里出错了?我认为您需要创建
选择然后选择选项。如果你没有选择,那么它就是无法选择
选择的示例(选项位于选择的内部):
沃尔沃汽车
萨博
梅赛德斯
奥迪
我认为您需要创建选择,然后选择选项。如果你没有选择,那么它就是无法选择
选择的示例(选项位于选择的内部):
沃尔沃汽车
萨博
梅赛德斯
奥迪
但这将创建另一个select控件。select已存在于源代码中…请仔细查看!它位于您通过JavaScript收到的源代码中。您是否也在mechanize中获得了它(没有JavaScript)?是的,它能够找到select控件,但我需要向它添加另一个元素。请帮助我创建另一个select控件。select已存在于源代码中…请仔细查看!它位于您通过JavaScript收到的源代码中。您是否也在mechanize中获得了它(没有JavaScript)?是的,它能够找到select控件,但我需要向它添加另一个元素。请帮帮我
br.form.new_control('text','option',{'value':'327'})
br.form.fixup()
br.form['mDdlOtherIndex']= ['327']
File "build\bdist.win-amd64\egg\mechanize\_form.py", line 2006
mechanize._form.ItemNotFoundError: insufficient items with name '327'
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>