0
votes

I need to process list tags in order to extract data from them. The problem is that I need to analyze each list separably. I tried something like this:

List<HtmlAgilityPack.HtmlNode> tl = new List<HtmlNode (doc1.DocumentNode.SelectNodes("//ul"));

I was expecting that every tl element will be separate ul list, but it turns out that tl has only one element containing all li tags in html document. What am I doing wrong?

1

1 Answers

0
votes

I've solved the problem with following code:

 foreach (HtmlAgilityPack.HtmlNode node in tk)
                                    {

                                        if (node.ParentNode.Name == "ul" || node.ParentNode.Name == "ol")
                                        {
                                            List<string> sh=new List<string>();
                                            var t = node.ParentNode.Elements("li");
                                            for(int i=0;i <t.Count();i++)
                                             sh.Add(t.ElementAt(i).InnerText);

                                            uoList.Add(sh);
                                        }
                                    }

Now every uoList list member represents an ul or ol element which contains all li element's inside that element.