Html Agility Pack - loop through rows and columns

前端 未结 2 947
别那么骄傲
别那么骄傲 2021-01-16 02:13

How can I loop through table and row that have an attribute id or name to get inner text in deep down in each td cell? I work on asp.net, c#, and the newest html agility pac

相关标签:
2条回答
  • 2021-01-16 02:51

    You need to select these nodes using xpath:

    foreach(HtmlNode cell in doc.DocumentElement.SelectNodes("//tr[@name='display']/td")
    {
       // get cell data
    }
    
    0 讨论(0)
  • 2021-01-16 03:07

    It worked! Thank you very much Oded.

        HtmlDocument doc = new HtmlDocument();
             doc.Load(@"C:/samplefolder/sample.htm"); 
    foreach(HtmlNode cell in doc.DocumentNode.SelectNodes("//tr[@name='display']/td")) 
    {
             string test = cell.InnerText;
             Response.Write(test); 
    }
    

    It showed result like JanFebMarAprMayJuneJulAugSepOctNovDec. How can I sort them out, separate by a space or a tab? Thank you.

    0 讨论(0)
提交回复
热议问题