How to get all values inside a div as a string using HtmlAgilityPack

c# html html-agility-pack

Question

I have an html that i need to extract just a div and the elements inside this div but as a string.

 <div id=01>
    <div id-02>
      <label></labell>
      <input></input>
       //etc
     </div>
 </div>

How do i get all inside the div 01 as a single string?

The only way i found is to get using the nodes, but it returns me a collection of HtmlNodes.

document.DocumentNode.SelectNodes("//*[contains(@class,'container')]").Descendants("div").Select(p => p.OuterHtml);
1
0
5/1/2018 2:42:14 AM

Popular Answer

var Node = document.DocumentNode.SelectNodes("//div[@id='01']").SingleOrDefault();
var target = Node.InnerHtml;

becouse id is single I used SingleOrDefault for this id

1
10/8/2015 5:06:55 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow