|

楼主 |
发表于 2016-5-27 21:41:43
|
显示全部楼层
void CNavigateView::OutputElement(CComQIPtr<IHTMLElement> pElement)
{
if(pElement != NULL)
{
CComBSTR bstr;
if(SUCCEEDED(pElement->get_tagName(&bstr)))
{
CStringA text(bstr);
TRACE("标签=[%s]\t",text);
}
if(SUCCEEDED(pElement->get_className(&bstr)))
{
CStringA text(bstr);
TRACE("类名=[%s]\t",text);
}
if(SUCCEEDED(pElement->get_outerText(&bstr)))
{
CStringA text(bstr);
text.Replace('\r',' ');
text.Replace('\n',' ');
text.Trim();
TRACE("内容=[%s]\t",text);
}
TRACE("\n");
}
}
void CNavigateView::ListAllElement()
{
CComPtr<IDispatch> spDispDoc = CHtmlView::GetHtmlDocument();
CComQIPtr<IHTMLDocument2> pHtmlDoc2 = spDispDoc;
//IHTMLDocument2* pHtmlDoc2 =(IHTMLDocument2*)CHtmlView::GetHtmlDocument();
do
{
if(pHtmlDoc2 == NULL)
{
break;
}
CComQIPtr<IHTMLElementCollection> pCollection;
if(!SUCCEEDED(pHtmlDoc2->get_all(&pCollection)) || pCollection==NULL)
{
break;
}
long labelCount = 0;
if(!SUCCEEDED(pCollection->get_length(&labelCount)))
{
break;
}
for(long i=0 ; i<labelCount ; i++)
{
CComPtr<IDispatch> pIDisp = NULL;
if(!SUCCEEDED(pCollection->item(CComVariant(i),CComVariant(0),&pIDisp)) || pIDisp==NULL)
{
break;
}
CComQIPtr<IHTMLElement> pElement = pIDisp;
OutputElement(pElement);
}
}while (FALSE);
}
|
|