C# 如何将mshtml.ihtmlidevelment强制转换为mshtml.htmlidevelementclass?
如何将mshtml.ihtmlidevelment转换为mshtml.htmlidevelementclassC# 如何将mshtml.ihtmlidevelment强制转换为mshtml.htmlidevelementclass?,c#,.net,mshtml,C#,.net,Mshtml,如何将mshtml.ihtmlidevelment转换为mshtml.htmlidevelementclass IHTMLElementCollection collection = doc.body.all; foreach (var htmlElem in collection) { if (htmlElem is mshtml.IHTMLDivElement) { mshtml.IHTMLDivElement div = htmlElem as msht
IHTMLElementCollection collection = doc.body.all;
foreach (var htmlElem in collection)
{
if (htmlElem is mshtml.IHTMLDivElement)
{
mshtml.IHTMLDivElement div = htmlElem as mshtml.IHTMLDivElement;
if (div != null)
{
// HTMLDivElementClass divClass = (HTMLDivElementClass)div; ?????????
}
}
}
我需要访问HTMLDivElementClass才能获取它的所有成员
您的代码几乎正确。不知道你想要什么 请按如下方式更改您的代码
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;
foreach (var htmlElem in collection)
{
if (htmlElem is mshtml.IHTMLDivElement)
{
mshtml.HTMLDivElementClass div = htmlElem as mshtml.HTMLDivElementClass;
if (div != null)
{
//DO YOUR CODE HERE
//div.IHTMLElement_id
}
}
}
它适用于我,在“div”中,对象的类型为“htmldevelementclass”
还有一个建议,如果您只想从页面中删除所有DIV标记,请使用下面的代码行
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.getElementsByName("div");
而不是
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;
这将删除检查元素是否为DIV的条件
希望这对您有所帮助。您的代码几乎正确。不知道你想要什么 请按如下方式更改您的代码
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;
foreach (var htmlElem in collection)
{
if (htmlElem is mshtml.IHTMLDivElement)
{
mshtml.HTMLDivElementClass div = htmlElem as mshtml.HTMLDivElementClass;
if (div != null)
{
//DO YOUR CODE HERE
//div.IHTMLElement_id
}
}
}
它适用于我,在“div”中,对象的类型为“htmldevelementclass”
还有一个建议,如果您只想从页面中删除所有DIV标记,请使用下面的代码行
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.getElementsByName("div");
而不是
mshtml.IHTMLElementCollection collection = (mshtml.IHTMLElementCollection)objDocument.body.all;
这将删除检查元素是否为DIV的条件
希望这对你有所帮助。你为什么要做演员?您注释掉的代码有什么问题?@vcsjones,因为我无法访问HtmlVelectClass中所需的所有属性。iHTMLIDevement只有两个属性。。。例如,我需要获得该部门的ID等…为什么你需要做演员?您注释掉的代码有什么问题?@vcsjones,因为我无法访问HtmlVelectClass中所需的所有属性。iHTMLIDevement只有两个属性。。。例如,我需要获取DIV的ID等。。。