테이블을 포함하는 HTML 페이지가 있고 C # 창 폼에서 해당 테이블을 구문 분석하고 싶습니다.
이 웹 페이지를 내가 해보고 싶은 구문입니다.
> Foreach(Htmlnode a in document.getelementbyname("tr"))
{
richtextbox1.text=a.innertext;
}
나는 이것과 같은 어떤 것을 시도했다. 그러나 나는 표 형식으로 나를 줄 뿐이다. 왜냐하면 나는 모든 영어 문장을 인쇄하고 있기 때문에 나의 고마움에 대해 유감스럽게 생각한다.
WebClient webClient = new WebClient();
string page = webClient.DownloadString("http://www.mufap.com.pk/payout-report.php?tab=01");
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(page);
List<List<string>> table = doc.DocumentNode.SelectSingleNode("//table[@class='mydata']")
.Descendants("tr")
.Skip(1)
.Where(tr=>tr.Elements("td").Count()>1)
.Select(tr => tr.Elements("td").Select(td => td.InnerText.Trim()).ToList())
.ToList();
이런 뜻인가요?
foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table")) {
///This is the table.
foreach (HtmlNode row in table.SelectNodes("tr")) {
///This is the row.
foreach (HtmlNode cell in row.SelectNodes("th|td")) {
///This the cell.
}
}
}