C++ 从IE DOM获取HTML头部

C++ 从IE DOM获取HTML头部,c++,html,internet-explorer,dom,head,C++,Html,Internet Explorer,Dom,Head,我知道如何使用IHTMLDocument2接口(通过调用get_body成员函数)获取文档的HTML正文 但是我怎样才能得到头部呢?IHTMLDocument2界面中没有这样的功能。CComPtr htmlDocument; CComPtr<IHTMLDocument2> htmlDocument; CComPtr<IHTMLElementCollection> elementCollection; htmlDocument->get_al

我知道如何使用IHTMLDocument2接口(通过调用get_body成员函数)获取文档的HTML正文

但是我怎样才能得到头部呢?IHTMLDocument2界面中没有这样的功能。

CComPtr htmlDocument;
    CComPtr<IHTMLDocument2> htmlDocument;
    CComPtr<IHTMLElementCollection> elementCollection;

    htmlDocument->get_all(&elementCollection);
    for (long i=0;i<numberOfElements;i++)
    {
        _variant_t index = i;
        CComPtr<IHTMLElement> htmlElem;
        CComPtr<IDispatch> htmlElemDisp;
        hResult = elementCollection->item( index,index ,(IDispatch **) &htmlElemDisp );
        if (FAILED(hResult) || (!(htmlElemDisp)))
        {
            continue;
        }
        hResult = htmlElemDisp->QueryInterface( IID_IHTMLElement ,(void **) &htmlElem);
        if (FAILED(hResult) || (!(htmlElem)))
        {
            continue;
        }
        hResult = htmlElem->get_tagName(&buffer);

        if (FAILED(hResult) || (!(buffer)))
        {
            continue;
        }
        if (_wcsicmp(buffer,L"HEAD")==0) 
        { 
         // your code here
        }
}
CComPtr元素集合; htmlDocument->get_all(&elementCollection); 对于(长i=0;项目(索引,索引,(IDispatch**)和htmlElemDisp); if(失败(hResult)| |(!(htmlElemDisp))) { 持续 } hResult=htmlElemDisp->QueryInterface(IID_IHTMLElement,(void**)和htmlElem); if(失败(hResult)| |(!(htmlElem))) { 持续 } hResult=htmlElem->get_标记名(&buffer); if(失败(hResult)| |(!(缓冲区))) { 持续 } 如果(_wcsicmp(缓冲区,L“头”)==0) { //你的代码在这里 } }
此外,您还可以使用
IHTMLDocument2*htmlDocument
而不是
CComPtr htmlDocument
。 其主要思想是获取文档中的所有元素,对它们进行迭代,并找到具有标记名头的元素。 希望这能有所帮助。

CComPtr htmlDocument;
CComPtr元素集合;
htmlDocument->get_all(&elementCollection);
对于(长i=0;项目(索引,索引,(IDispatch**)和htmlElemDisp);
if(失败(hResult)| |(!(htmlElemDisp)))
{
持续
}
hResult=htmlElemDisp->QueryInterface(IID_IHTMLElement,(void**)和htmlElem);
if(失败(hResult)| |(!(htmlElem)))
{
持续
}
hResult=htmlElem->get_标记名(&buffer);
if(失败(hResult)| |(!(缓冲区)))
{
持续
}
如果(_wcsicmp(缓冲区,L“头”)==0)
{ 
//你的代码在这里
}
}
此外,您还可以使用
IHTMLDocument2*htmlDocument
而不是
CComPtr htmlDocument
。 其主要思想是获取文档中的所有元素,对它们进行迭代,并找到具有标记名头的元素。 希望这有帮助