html로 된 테이블을 파싱 할 필요가 있습니다.
<html>
<head>
<title>
</title>
</head>
<body>
<table>
***contents***
</table>
</body>
</html>
내 코드는 다음과 같습니다.
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(@path);
foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table"))
{
foreach (HtmlNode row in table.SelectNodes("tr"))
{
foreach (HtmlNode cell in row.SelectNodes("th|td"))
{
***copy content***
}
}
}
하지만 다음 NullReferenceException 얻을
foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table"))
그래서 테이블에는 그 안에 아무 것도 없지만 왜 그럴까요?
HTML에 tr의 테이블 행이 없으므로 민첩성 팩은 아무 것도 찾지 못합니다.
try this
// Get all tables in the document
HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table");
// Iterate all rows in the first table
HtmlNodeCollection rows = tables[0].SelectNodes(".//tr");
for (int i = 0; i < rows.Count; ++i)
{
}