User Tools

Site Tools


Action disabled: source
blog:2025-03-12-005



2025-03-12 Parsing HTML Table in C#

Local Backup

  • I have an html page which contains a table and i want to parse that table in C# windows form
  • this is the webpage i want to parse i have tried
  • > Foreach(Htmlnode a in document.getelementbyname("tr"))
    {
        richtextbox1.text=a.innertext;
    }
  • i have tried some thing like this but it wont give me in tabular form as i am simply printing all trs so please help me regarding this thanx sorry for my english.

Answers

  • 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();

TAGS

  • 49 person(s) visited this page until now.

blog/2025-03-12-005.txt · Last modified: 2025/03/12 14:01 (external edit)