Search code examples
.nethtml-agility-pack

Htmlagilitypack. Select div by class and position


I need to get certain div by class name and position. I know that in order to get some tag by class i write: tag[@class='class_name'].But there are 2 tags with same class name so i get both. Is it possible to get only the first one? Thanks!


Solution

  • There are several way, the most commons are:

    First one:

    var firstDiv= res.SelectSingleNode("//div[1]");
    

    Second one:

     var firstDiv= res.Descendants("div").FirstOrDefault();
    

    Good Luck!