C# - Get value of tr in html

后端 未结 1 1764
一个人的身影
一个人的身影 2021-01-28 17:13

I start my code with:

        private int GetSizeOf(IEnumerable tables)
        {
            int size = 0;
            var infos = tables.Elemen         


        
相关标签:
1条回答
  • 2021-01-28 18:06
    var doc = new HtmlAgilityPack.HtmlDocument();
    doc.Load(...);
    
    var element = doc.DocumentNode
        .Element("html")
        .Element("body")
        .Element("div")
        .Element("center");
    
    var trs = element.Element("table").Elements("tr").ToArray();
    var array = new string[trs.Length, trs[0].Elements("td").Count()];
    
    for (int row = 0; row < trs.Length; row++)
    {
        var tds = trs[row].Elements("td").ToArray();
    
        for (int col = 0; col < tds.Length; col++)
        {
            array[row, col] = tds[col].InnerText;
        }
    }
    
    0 讨论(0)
提交回复
热议问题