Htmlagilitypack select the subsidiary element



  • var td = htmlNode.SelectNodes("td").Select(x => x.InnerText).ToList();
    <td align="right">
         <img src="templates/images/countmax.png"></td>
    

    In variable td Only elements with currents tdbut I would like to see the Gate img I saw him, too.



  • Your code can be rewritten:

    var tdElements = htmlNode.SelectNodes("td").ToList();
    

    Now the variable tdElements contains a list of objects HtmlNodeeach of which corresponds to the element <td> and contains all the information provided. In particular, from the collection tdElements[0].ChildNodes a subsidiary may be removed <img>:

    var imgElement = tdElements[0].ChildNodes.FindFirst("img");
    

    And still, there's a way to extract `InnerText' from each element:

    var innerText = tdElements[0].InnerText;
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2