mshtml一些用法

获取某个tags集合   CStringallPointData;             IDispatch*pDisp=webbrowser.get_Document();   IHTMLDocument2*pDocument;    IHTMLElementCollection*pCollection;

大家好,又见面了,我是你们的朋友全栈君。

获取某个tags集合    

 CString allPointData;     

              

    IDispatch *pDisp = webbrowser.get_Document();  

    IHTMLDocument2* pDocument;   

    IHTMLElementCollection* pCollection;  

   

    pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);      

    HRESULT hr;  

    hr = pDocument->get_all(&pCollection);  


//hr=pDocument->get_scripts(&pCollection);


VARIANT varID;  


varID = StringToVariant((CString)”TABLE”);      


pCollection->tags(varID,&pDisp);

    IHTMLElementCollection* Collection;  


pDisp->QueryInterface(&Collection);


long celem;  

Collection->get_length(&celem);

IHTMLScriptElement用法

  CString allPointData;     
              
    IDispatch *pDisp = webbrowser.get_Document();  
    IHTMLDocument2* pDocument;   
    IHTMLElementCollection* pCollection;  
   
    pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);      
    HRESULT hr;  
    hr = pDocument->get_all(&pCollection);  
//hr=pDocument->get_scripts(&pCollection);
//VARIANT varID;  
// varID = StringToVariant((CString)”TABLE”);      
//pCollection->tags(varID,&pDisp);
    //IHTMLElementCollection* Collection;  
//pDisp->QueryInterface(&Collection);
long celem;  
//Collection->get_length(&celem);

    if( hr == S_OK )  
    {  
       
        hr = pCollection->get_length(&celem);   //得到所有节点的个数用以遍历  
        if( hr == S_OK )  
        {  
            VARIANT varIndex, var;  
            for ( int i = 0; i < celem; i++ )  
            {  
                varIndex.vt = VT_UINT;  
                varIndex.lVal = i;  
                VariantInit(&var);  
                hr = pCollection->item(varIndex,var,&pDisp);  
                if ( hr == S_OK )  
                {   
                    //IHTMLElement *pElement; 
IHTMLScriptElement *pScriptElement;
                    hr = pDisp->QueryInterface(IID_IHTMLScriptElement,(void**)&pScriptElement);  
                    if ( hr == S_OK )  
                    {  
                        CString pointData,id;  
                        BSTR bs= SysAllocString(L””);
                        //pElement->get_id(&bs); 
//pElement->get_className(&bs);
pScriptElement->get_src(&bs);
                        id = CString(bs);  
                        if ( id == _T(“d:\ni.js”))  
                        {  
                            //IHTMLInputElement* input;  
                            //hr = pDisp->QueryInterface(IID_IHTMLInputElement,(void**)&input);  
                            //input->get_value(&bs);   //将id为LanLonPoints中的value值赋给bs  
                            //pointData = CString(bs);  
                            //allPointData = pointData;
VARIANT index;   
                             VARIANT varID;   
                             V_VT(&index) = VT_I4;   
                             V_I4(&index) = 1;
                             CString strInfo;
IHTMLTable * pTable;  // 获得表格元素接口
        hr = pDisp->QueryInterface(IID_IHTMLTable,(void **)&pTable ); 
        if ( (hr == S_OK) && (pTable != NULL) )   
        {   
            IHTMLElementCollection* pColl2 = NULL;   
pTable->get_rows(&pColl2); // 获取表格行   
            IDispatch* pDisp2;   
            V_I4(&index) = 1;   
            hr = pColl2->item( index,index, &pDisp2 );                 // 获取第2行位置   
            if ( (hr == S_OK) && (pDisp2 != NULL) )   
            {   
                IHTMLTableRow* pRow;                                   // 获取行元素接口   
                hr = pDisp2->QueryInterface(IID_IHTMLTableRow,(void **)&pRow);   
                if( (hr == S_OK) && (pRow != NULL) )   
                {   
                    IHTMLElementCollection* pColl3 = NULL;   
                    pRow->get_cells(&pColl3);                          // 获取格子元素   
                    IDispatch* pDisp3;   
                    V_I4(&index) = 1;     
                    hr = pColl3->item( index,index, &pDisp3 );         // 获取第2行第2格元素   
                    if ( (hr == S_OK) && (pDisp2 != NULL) )   
                    {   
                        IHTMLElement* pElem;                           // 获取元素接口   
                        hr = pDisp3->QueryInterface(IID_IHTMLElement,(void **)&pElem);   
                        if( hr == S_OK )   
                        {   
                            BSTR bstr = SysAllocString(L””);   
                            pElem->get_innerText(&bstr);               // 获取该表格元素的文本信息   
                            strInfo =bstr;   
//MessageBoxExA(NULL,strInfo,NULL,NULL,NULL);
                            pElem->Release();   
                        }   
                        pDisp3->Release();   
                    }   
                    pRow->Release();   
                }   
                pDisp2->Release();   
            }   
            pTable->Release();   
        }   
        pDisp->Release();   

                    }  
                }  
            }  
        }  
    }   

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/127038.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 系统管理命令crontab

    系统管理命令crontab

    2021年6月6日
    124
  • 常见的杀毒软件_杀毒软件什么最好

    常见的杀毒软件_杀毒软件什么最好如果没有360,杀毒软件哪家强?

    2022年8月20日
    7
  • matlab灰度gui,matlabgui灰度变化

    matlab灰度gui,matlabgui灰度变化课程设计报告册?课程名称:课题名称:专业班级:姓名:MATLAB课程设计灰度变换增强BobWang学号:信息楼22015164课程设计主要场所:时间:……《数字视音频技术》课程设计报告题目:基于MATLABGUI的数字图像处…学号:20994055003数字图像处理论文二〇一二年十月基于灰度变换的图像增强及Matlab实现摘…

    2022年5月23日
    34
  • linuxshell(find sed awk vi)-note

    linuxshell(find sed awk vi)-note

    2021年8月29日
    75
  • VeryCD转型的应对措施,让我们继续分享互联网!!!

    VeryCD转型的应对措施,让我们继续分享互联网!!!
    昨天在家里,看着电影听着歌,忽然VeryCD就被和谐了!有电驴的日子才是好日子啊!我还想下【告白】呢!我还想下【大地惊雷】呢!……
    已经有不少同学注意到了,VeryCD的音乐区被和谐了,电影区和剧集区也不提供下载链接了,俨然变成一个在线视频网站。那么高清电影、剧集,音乐专辑、电影原声就此离我们远去了?不!
    VeryCD怂掉也是迟早的事儿,它在中国光明正大的推广盗版如此之久已经是一个奇迹了,但VC倒了并不会影响我们下载emule资源。简单来说VeryCD是一个商业公司,

    2022年7月15日
    18
  • lvs keepalived「建议收藏」

    lvs keepalived「建议收藏」集群是一种并行或分布式系统,该系统包括一个互联的整体计算机集合作为一种单一统一的计算资源使用。通过集群技术。我们可以在付出较低成本的情况下获得在性能可靠性灵活性更高的收益。计算机集群简称集群。是一组计算机系统。通过松散集成的计算软件和硬件连接起来。高度紧密的协作完成计算相关工作。集群是指一组互相独立的计算机,利用高速通信网络组成的一个计算机系统。每个集群节点(每个计算机)都是运行其自己进

    2022年7月23日
    19

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号