使用HtmlAgilityPack,如何从输入隐藏值中获取数据,如何从HTML表中获取C#中的数据?
我需要输入tr,td rate的隐藏值。如何在html下面的表格中获取该信息?
<table>
<caption>
<div id="cal_nav"
class="float_right">
<ul class="inline">
<li>
<a href="#"
onClick="changeRatesView('calendar')">Calendar View</a>
</li>
<li id="previous"
class="first">
<a title="September"
- "2015"
href="#"
onClick="searchPrevMonthAvailability()"> </a>
</li>
</div>
</caption>
<thead>
<tr>
<th>Date</th>
<th>Occupancy</th>
<th>Net Rate</th>
<th>Sell Rate</th>
</tr>
</thead>
<tbody>
<input type="hidden"
name="rateid"
value="234154166">
<tr>
<td>1</td>
<td>single</td>
<td>1652</td>
<td>2500</td>
</tr>
<tr>
<td>2</td>
<td>single</td>
<td>1454</td>
<td>4344</td>
</tr>
<input type="hidden"
name="rateid"
value="234154134">
<tr>
<td>1</td>
<td>single</td>
<td>1652</td>
<td>2500</td>
</tr>
<tr>
<td>2</td>
<td>single</td>
<td>1454</td>
<td>4344</td>
</tr>
<input type="hidden"
name="rateid"
value="234154145">
<tr>
<td>1</td>
<td>single</td>
<td>1652</td>
<td>2500</td>
</tr>
<tr>
<td>2</td>
<td>single</td>
<td>1454</td>
<td>4344</td>
</tr>
</tbody>
</table>
MY Linq代码:
var tds= (from td in doc.DocumentNode.Descendants("table")
select td).ToList()[2].ChildNodes[2];
var trer = tdsyh.SelectNodes("//input[@type='hidden' and @name='rateid']|tr").Select(x => x).ToList();
答案 0 :(得分:0)
您可以尝试以下内容:
var hiddenFields = doc.DocumentNode.Descendants("input").Where(_ => _.GetAttributeValue("type", "").Equals("hidden") && _.Name.Equals("rateid"));