我在表中的许多表行中有这个 html:
.........
<tr class="greycellodd" align="right">
<td align="left">
<input type="checkbox" name="cashInvestment" value="100468057"/>
</td>
<td align="left">Cardcash
</td>
<td class="nobr">26 Aug 10</td>
<td class="nobr"> 1.00
</td>
<td class="nobr"> 1.00
</td>
<td align="right">£</td>
<td class="nobr">0.00 </td>
<td class="nobr">0.00 </td>
<td class="nobr">
<span class="changeupsmall">1.00 </span>
</td>
</tr>
<tr class="greycellodd">
<td align="right"/>
<td class="nobr" colspan="8">VISA</td>
</tr>
<tr class="greycelleven" align="right">
<td align="left">
<input type="checkbox" name="cashInvestment" value="100480214"/>
</td>
<td align="left">Santander
</td>
<td class="nobr">24 Sep 11</td>
<td class="nobr"> 1.00
.......
我需要提取每个复选框标签之间的所有内容
<input type="checkbox" name="cashInvestment" ../>
例子
元素 1:
Cardcash
26 Aug 10
1.00
1.00
£
0.00
0.00
1.00
VISA
要素 2:
Santander
24 Sep 11
1.00
.......
我试过了:
Elements Inve = mainFirst.select("input ~ *" );
和
Elements Inve = doc.select("input"); // gives me nothing as there is no text to the input tag (it has no child).
我还需要获取复选框的值,我知道该怎么做,但如果可能的话,最好同时做:
Elements mainTables = doc.select("table.maintable");
for (Element subTable : mainTables){
Elements borrowInve = subTable.select("input[type=checkbox][name=cashInvestment]" );
String attr = test.attr("value");
}
谢谢
编辑:通过检查大小解决:
Elements td = tableRows.get(i).select("td");
Elements cash = tableRows.get(i).getElementsByAttributeValue("name", attrValue); // check if checkbox is present
int theSize = cash.size();
if(theSize ==1){ // this row is not a comment
String checkbox = "";
Element cbox = td.select("input[type=checkbox]" ).first();
checkbox = cbox.attr("value");
else if (theSize ==0){ // this row contains a comment
.............