IHTMLDocument2 好像只能得到body源码,IHTMLDocument2能得到head源码吗?或者其他方法得到!

解决方案 »

  1.   

    void xxxxxxxx_html::bianli_all(IHTMLDocument2 *pdd,CString tagetName){
    try
    {
    CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pd2=pdd;
    if(!pd2)return;
    CComPtr<IHTMLElement> pli=NULL;
    CString sa;
    BSTR bs=NULL;
    //***************************************************
    CComPtr<IHTMLElementCollection> pecel=NULL; 
    if(pd2->get_all(&pecel)==S_OK&&pecel.p!=NULL)

    CComPtr<IDispatch> pDisp=NULL; 
    if(pecel->tags(COleVariant(tagetName),&pDisp)==S_OK&&pDisp!=NULL)

    LONG celem; 
    CComQIPtr<IHTMLElementCollection, &IID_IHTMLElementCollection> pecel2(pDisp); 
    if(pecel2!=NULL&&pecel2->get_length(&celem)==S_OK)

    //CString kkj;kkj.Format("%ld",celem);
    //MessageBox(kkj,"提示");//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&for(int i=0;i<celem;i++)

    if(pecel2->item(CComVariant(i),CComVariant(i),&pDisp)!=S_OK||pDisp==NULL)continue;
    if(pDisp->QueryInterface(&pli)!=S_OK||pli==NULL)continue;
    if(pli->get_innerHTML(&bs)!=S_OK)continue;
    sa=(CString)bs;//**************
    //*********//***********
    }//for
    }
    if(pecel2)pecel2.Release();
    }
    }
    if(pecel)pecel.Release();
    if(pli)pli.Release();
    if(pd2)pd2.Release();
    if(p)p.Release();
    if(bs)::SysFreeString(bs);
    }
    catch(...){}
    }