Search code examples
c#htmlgetelementsbytagname

How to Get the content of html tag in c#


I want to get the content in the "p" tag from HTML document

<div id=123>
  <div class="abc">

       <div class="xyz">
         <p>
             this is the contents
         </p>

I use

dynamic document = webControl1.ExecuteJavascriptWithResult("document");
var p = document.getElementsByTagName("p");

but it doesn't work


Solution

  • This works

    dynamic document = webControl1.ExecuteJavascriptWithResult("document");
    var p = document.getElementsByTagName("p");
      for (int i = 0; i < p.length; i++)
                {
                    MessageBox.Show(p[i].innerText) ;
    
                }