Parsing html with html agility pack

后端 未结 1 1512
小蘑菇
小蘑菇 2021-01-28 18:58

I want to collect all tags in from this div but do not know how to do this in the best way with xpath method


                      
相关标签:
1条回答
  • 2021-01-28 19:48
    HtmlDocument html = new HtmlDocument();
    html.Load(new StringReader(result));
    var anchorTags = html.DocumentNode.SelectNodes("//div[@class='biz_info']//a")
                         .Select(a => a.OuterHtml)
                         .ToList();
    

    That will give you list of anchor tags html. If you need just urls:

    urls = html.DocumentNode.SelectNodes("//div[@class='biz_info']//a[@href!='']")
               .Select(a => a.Attributes["href"].Value)
               .ToList();
    
    0 讨论(0)
提交回复
热议问题