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
}
}
Также вы можете использовать IHTMLDocument2* htmlDocument
вместо CComPtr<IHTMLDocument2> htmlDocument
.
Основная идея состоит в том, чтобы получить все элементы в вашем документе, итерировать их и найти тот, который имеет tagName HEAD.
Надеюсь, это поможет.