HTMLAgilityPack을 사용하여 각 행에 특정 셀을 가져 오려고합니다.모든 HTML 테이블 행의 첫 번째 및 두 번째 셀 가져 오기
foreach (HtmlNode row in ContentNode.SelectNodes("descendant::tr"))
{
//Do something to first cell
//Do something to second cell
}
세포가 더 많으며 각 세포에는 특별한 치료가 필요합니다. XPath를 사용하여이 작업을 수행하는 방법이 있지만 실제로는 쓸모가 없습니다. 즉
// from row
var firstCell = row.SelectSingleNode("td[1]");
// each first cell in a table (note: tbody is not always there)
var allFirstCells = table.SelectNodes("tbody/tr/td[1]");
, 사용 대괄호 셀 번호 : 다음 행의 자식 각각의 첫 번째 셀을 얻으려면, 당신이 할 수있는
var cell1 = row.SelectSingleNode("descendant::td:first");
좋은 질문 (+1). 원하는 노드를 정확히 선택하는 한 줄짜리 XPath 식에 대한 답을보십시오. –