我有一個表是這樣的:HTML敏捷包解析表
<table border="0" cellpadding="0" cellspacing="0" id="table2">
<tr>
<th>Name
</th>
<th>Age
</th>
</tr>
<tr>
<td>Mario
</td>
<th>Age: 78
</td>
</tr>
<tr>
<td>Jane
</td>
<td>Age: 67
</td>
</tr>
<tr>
<td>James
</td>
<th>Age: 92
</td>
</tr>
</table>
,我使用的HTML敏捷包解析它。我曾嘗試這個代碼,但它沒有返回預期的結果:下面是代碼:
foreach (HtmlNode tr in doc.DocumentNode.SelectNodes("//table[@id='table2']//tr"))
{
//looping on each row, get col1 and col2 of each row
HtmlNodeCollection tds = tr.SelectNodes("td");
for (int i = 0; i < tds.Count; i++)
{
Response.Write(tds[i].InnerText);
}
}
我得到的每一列,因爲我想這樣做對某些內容的處理返回。
我在做什麼錯?
你會得到什麼?什麼是錯誤?你得到了什麼? – 2013-02-20 19:20:24
頁面只是保持循環,所以我假設一個無限循環。類型'System.OutOfMemoryException'的異常被拋出。 – mpora 2013-02-20 19:45:44
http://stackoverflow.com/questions/14968729/html-agility-pack-loop-through-table-rows-and-columns/14990726#14990726 – mpora 2013-02-20 21:59:42