C# VB 调用方法是 webbrowser1.Document.all.tags("A").length这句就能得到网页中所有的超链数量VC 要怎么写呢?给点思路,谢谢~

解决方案 »

  1.   

    从webbrowser1得到IHTMLDocument2接口,再调用IHTMLDocument2中的all方法,得到IHTMLElementCollection接口,再调用IHTMLElementCollection中的tags方法大致流程是这样
      

  2.   

    一样的次序...
    IWebBrowser2::get_Document(&pDisp)
    pDisp->QueryInterface得到IHtmlDocument2
    IHtmlDocument2::get_all(&pCol)得到IHTMLElementCollection
    IHTMLElementCollection::tags(var, &pDisp)
    pDisp->QueryInterface得到IHTMLElementCollection
    IHTMLElementCollection::get_length得到数量
      

  3.   

    程序webbrowser中ID为IDC_EXPLORER1,我为其添加了一变量为m_web
    方法中只有一个
    LPDISPATCH get_Document()
    {
        LPDISPATCH result;
        InvokeHelper(0xcb, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    没有传参数。
    IWebBrowser2::get_Document(&pDisp)这句怎么来的?
    我初学VC,大侠耐心指点下~~~
      

  4.   

    CComQIPtr < IHTMLDocument2,&IID_IHTMLDocument2 > spDoc =m_web.get_Document();
    CComPtr <IDispatch> disp;
    CComQIPtr <IHTMLElementCollection ,&IID_IHTMLElementCollection> pColle;
    CComPtr <IHTMLAnchorElement> pAnchorElment;
    CComPtr <IHTMLElement> pEment;
    long nCun;
    BSTR bst;
    spDoc->get_links(&pColle);
    pColle->get_length(&nCun);
    for(long i =0; i<nCun; i++)
    {
       CString s,ss;
       _variant_t index = i;
       pColle->item(index,index,&disp);
       disp->QueryInterface(IID_IHTMLAnchorElement,(void**)&pAnchorElment);
       disp->QueryInterface(IID_IHTMLElement,(void**)&pEment);
       pAnchorElment->get_href(&bst);
       s=bst;
       pEment->get_innerText(&bst);
       ss=bst;
       ::AfxMessageBox(ss);
      
       pEment.Release();
       pAnchorElment.Release();
       disp.Release();
    }
    算是弄出来了。巨麻烦啊VC
      

  5.   

    c是麻烦...这些都是dispatch接口,给脚本用的。
      

  6.   


    pDisp = m_web->get_Document();