gpt4 book ai didi

javascript - Python 添加新控件会出现错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:58 25 4
gpt4 key购买 nike

我在 Python 中使用 mechanize 。我无法设置 SelectControl 元素的值。

我尝试抓取的网页是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>&nbsp;</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>&nbsp;</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>

现在我可以更改我正在执行的第二个单选按钮的值

br.select_form(nr=0)
br.set_all_readonly(False)
br.form['mTbFromDate']='08/01/2013'
br.form['mTbToDate']='08/08/2013'
br.form.set_value(['0'],name='mRbtLstSpotFut')

但我还想选择不存在的选项值“327”(因为单击单选按钮时它由 JS 出现, Mechanize 无法处理)

所以我尝试向表单添加一个新控件,例如

<option value="327">MCXENERGY</option>

我正在尝试这个,但这不起作用。

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 那么它就无法选择它。

选择示例(选项位于选择内部):

<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>

关于javascript - Python 添加新控件会出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18134401/

25 4 0
文章推荐: lisp - 可以使用 find 在另一个列表中查找列表吗?
文章推荐: c# - 将 System.DayOfWeek 转换为 Microsoft.Office.Interop.Outlook.OlDaysOfWeek
文章推荐: c# - 为 Serilog 创建一个包装器
文章推荐: css - 如何使 Opera 中透明
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com