我的xpath有问题;这是我的HTML数据:
<table id="availabilityTable0" class="w99 availabilityTable">
<tr>
<th scope="col" class="center">Waktu</th>
<th scope="col" class="center">Keberangkatan /
Tiba</th>
<th scope="col" class="center">Penerbangan</th>
<th scope="col" class="center">Harga Promo</th>
<th scope="col" class="center">Harga Normal</th>
</tr>
<tr class="altRowItem">
<td class="center">7:00 <BR>8:20 </td>
<td class="center">Batam<BR>Kuala Namu</td>
<td class="center">QG
885</td>
<td class="fareCol1"></td>
<td class="fareCol2">
<p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare4" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~Q~~Q~RGFR~~1~X|QG~ 885~ ~~BTH~05/19/2014 07:00~KNO~05/19/2014 08:20~">Rp.365,000
( Q/Cls;
4 )
</p>
<p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare5" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~P~~P~RGFR~~1~X|QG~ 885~ ~~BTH~05/19/2014 07:00~KNO~05/19/2014 08:20~">Rp.395,000
( P/Cls;
4 )
</p>
<p> </p></td>
</tr>
<tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare17">
<td colspan="5">
<div>
<table>
<tr>
<td colspan="5">
<div class="FareRulesTable-Normal-Left-AI">
<table>
<tr>
<td>
<h3>Fare Rules:</h3>ccc</td>
</tr>
<tr>
<td>ccc</td>
</tr>
<tr></tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare4">
<td colspan="5">
<div>
<table>
<tr>
<td colspan="5">
<div class="FareRulesTable-Normal-Left-AI">
<table>
<tr>
<td><h3>Fare Rules:</h3>ccc</td>
</tr>
<tr>
<td>ccc</td>
</tr>
<tr></tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td class="center">16:55 <BR>18:15 </td>
<td class="center">Batam<BR>Kuala Namu</td>
<td class="center">QG
883</td>
<td class="fareCol1"></td>
<td class="fareCol2">
<p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare18" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~P~~P~RGFR~~1~X|QG~ 883~ ~~BTH~05/19/2014 16:55~KNO~05/19/2014 18:15~">
Rp.795,000
( P/Cls;
4 )
</p>
<p><input id="ControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare19" type="radio" name="ControlGroupScheduleSelectView$AvailabilityInputScheduleSelectView$market1" value="0~O~~O~RGFR~~1~X|QG~ 883~ ~~BTH~05/19/2014 16:55~KNO~05/19/2014 18:15~">
Rp.820,000
( O/Cls;
4 )
</p>
<p> </p></td>
</tr>
<tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare30">
<td colspan="5">
<div>
<table>
<tr>
<td colspan="5">
<div class="FareRulesTable-Normal-Left-AI">
<table>
<tr>
<td>
<h3>Fare Rules:</h3>abc</td>
</tr>
<tr>
<td>abc</td>
</tr>
<tr></tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr class="trSSRMarketControlGroupScheduleSelectView_AvailabilityInputScheduleSelectView_RadioButtonMkt1Fare18">
<td colspan="5">
<div>
<table>
<tr>
<td colspan="5">
<div class="FareRulesTable-Normal-Left-AI">
<table>
<tr>
<td>
<h3>Fare Rules:</h3>abc</td>
</tr>
<tr>
<td>abc</td>
</tr>
<tr></tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
对不起,如果它需要很长的行...来自这个html,渲染应该像(切换为不重要的视图):
<radiobutton>Rp.365,000 ( Q/Cls; 4 )
<radiobutton>Rp.395,000 ( P/Cls; 4 )
<radiobutton>Rp.795,000 ( P/Cls; 4 )
<radiobutton>Rp.820,000 ( O/Cls; 4 )
但我希望它像:
<radiobutton>Rp.365,000 ( Q/Cls; 4 ) ---- <radiobutton>Rp.395,000 ( P/Cls; 4 )
<radiobutton>Rp.795,000 ( P/Cls; 4 ) ---- <radiobutton>Rp.820,000 ( O/Cls; 4 )
所有价格都在fareCol2 td元素基于table availabilityTable0 ..从我的代码中,我可以从第一个td fareCol2获得所有输入元素,但是下一个farecol2,我得到了空白
HtmlDocument doc = new HtmlDocument();
DataTable dt = new DataTable();
string htmldata = "";
string removeClassFare = string.Empty;
int index;
doc.LoadHtml(html);
var searchAvaibilityTable = doc.DocumentNode.SelectNodes(".//table[contains(@id, 'availabilityTable')]");
var searchAvaibilityTable1 = doc.DocumentNode.SelectNodes(".//table[contains(@id, 'availabilityTable0')]//td[@class='fareCol2']");
var searchAvaibilityTable2 = doc.DocumentNode.SelectNodes(".//table[@id='availabilityTable0']//tr[2]//td[@class='fareCol2']//input");
for (int i = 0; i < searchAvaibilityTable2.Count; i++)
{
try
{
index = searchAvaibilityTable2[i].ParentNode.InnerText.IndexOf("(");
if (index != -1)
{
removeClassFare = searchAvaibilityTable2[i].ParentNode.InnerText.Substring(0, index);
removeClassFare = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(removeClassFare)).Replace("??", "").Replace("Rp.", "").Trim();
}
else
{
removeClassFare = searchAvaibilityTable2[i].ParentNode.InnerText;
}
}
catch (Exception e)
{
removeClassFare = searchAvaibilityTable2[i].ParentNode.InnerText;
}
htmldata = htmldata + "<input <input onclick='faredetail(this.value, this.name)' id=\"" + searchAvaibilityTable2[i].Attributes["id"].Value + "\" type=\"radio\" value=\"" + searchAvaibilityTable2[i].Attributes["value"].Value + "\" name=\"" + searchAvaibilityTable2[i].Attributes["name"].Value + "\"><br>" + removeClassFare + " # ";
}
return htmldata;
//return searchAvaibilityTable.Count.ToString() + "-" + searchAvaibilityTable1.Count.ToString() + "-" + searchAvaibilityTable2.Count.ToString();
}
这段代码,我可以得到第一个fareCol2,如何获得下一个fareCol2,这样我就能得到我想要的视图?