我寫了一個應用程序,從表中取值並操作它們,我的問題是在我想要的表(無ID,類)之前有2個表。我想跳過他們去第三張桌子。我的代碼:如何跳過表格使用HtmlAgilityPack
HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table");
HtmlNodeCollection rows = tables[2].SelectNodes(".//tr");
foreach (HtmlNode item in rows)
{
/// my code//
}
我以爲代碼:表[2]指進入第三個表,但INFACT意味着需要3個表,有沒有辦法來定義spacific表或到表? (表中沒有id或類名)
如果我這樣做:HtmlNodeCollection tables = doc.DocumentNode.SelectNodes(「// table [3]」); HtmlNodeCollection rows = tables [2] .SelectNodes(「.// tr」);我得到了錯誤:索引超出範圍。必須是非負數且小於集合的大小。參數名稱:索引 – ogsMC 2013-02-19 13:42:33
@ogsMC:更改您的代碼從HtmlNodeCollection rows = tables [2] .SelectNodes(「.// tr」);至HtmlNodeCollection rows = tables.SelectNodes(「。// tr」);將得到工作.... – Pandian 2013-02-19 13:43:52
錯誤...我必須給他的索引後的「表」。 :*( – ogsMC 2013-02-19 13:47:53