2015-11-08 28 views

回答

1

我得到以下

enter image description here

當DOM加載和結算時,你會得到body.All是當前元素下的所有元素的HtmlElementCollection,截至https://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.all(v=vs.110).aspx

定義此表將有助於導航此結構 https://msdn.microsoft.com/en-us/library/system.windows.forms.htmldocument(v=vs.110).aspx

全部 - 獲取的實例,其中存儲文檔的所有對象HtmlElement

Body - 獲取BODY標籤的HtmlElement

這裏是你如何加載DOM

 // Construct DOM 
     HTMLDocument doc = new HTMLDocument(); 

     // Obtain the document interface 
     IHTMLDocument2 htmlDocument = (IHTMLDocument2)doc; 
     string htmlContent = "<!DOCTYPE html><html><body><h2>An unordered HTML list</h2><ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li></ul></body></html>"; 

     // Load the DOM 
     htmlDocument.write(htmlContent); 

     // Extract all body elements 
     IHTMLElementCollection allBody = htmlDocument.body.all; 


     // All page elements including body, head, style, etc 
     IHTMLElementCollection all = htmlDocument.all; 

     // Iterate all the elements and display tag names 
     foreach (IHTMLElement element in allBody) 
     { 
      Console.WriteLine(element.tagName); 
     } 
+0

這不回答這個問題。其實什麼是動態的C# –

+0

動態在C#中只是意味着在VB.NET的對象。你只是說doc.body.all是動態類型,我問它爲什麼是對象/動態 –

+0

Jim我添加了一個代碼示例來加載DOM,這應該爲你清除它。 – Markus

相關問題