说 dw1 是一个类型为 msthml.htmldocument 的变量
dw1.all 类型为 mshtml.ihtmlelementcollection
但是, dw1.body.all 类型是对象。
为什么会这样?
说得更直白点。
为什么 type ofdw1.all
与type of 不同dw1.body.all
?
说 dw1 是一个类型为 msthml.htmldocument 的变量
dw1.all 类型为 mshtml.ihtmlelementcollection
但是, dw1.body.all 类型是对象。
为什么会这样?
说得更直白点。
为什么 type ofdw1.all
与type of 不同dw1.body.all
?
我得到以下
当 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
All - 获取 HtmlElementCollection的实例,该实例存储文档的所有 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);
}