C#中如何获取html标签的内容

How to Get the content of html tag in c#

我想从HTML文档

中获取"p"标签中的内容
<div id=123>
  <div class="abc">

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

我用

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

但是没用

尝试以下操作:

var p = document.getElementsByTagName("p")[0].innerHTML;

这个有效

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

            }