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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • html javascript_dom节点

    html javascript_dom节点Hereisalittlecodethatisuseful.varuiHelper=function(){varhtmls={};vargetHTML=function(url){///ReturnsHTMLinastringformat///TheurltothefilewiththeHTMLif(!htmls[url]){v…

    2022年9月12日
  • 工欲善其事,必先利其器之—使用OpenGrok阅读源码

    工欲善其事,必先利其器之—使用OpenGrok阅读源码OpenGrok的介绍OpenGrokisafastandusablesourcecodesearchandcrossreferenceengine.Ithelpsyousearch,cross-referenceandnavigateyoursourcetree.Itunderstandsvariousprogramfilefor…

    2022年5月25日
  • linux挂载磁盘教程「建议收藏」

    linux挂载磁盘教程「建议收藏」本文中的磁盘/dev/sdb为笔者测试服务器上的命名,在您的服务器中可能是/dev/xdb、/dev/vdb、/dev/xvdb等等请根据实际情况进行修改.1、创建挂载目录mkdir-p/www2、确认是否没有分区的磁盘,如下图,没有分区的磁盘是/dev/sdb,在您的服务器中可能是/dev/vdb,请注意按照实际名称修改fdisk-l3、为磁盘分区,若已分区,可跳过fdisk/dev/sdb4、输入n开始创建分区5、输…

    2022年6月19日
  • eclipse使用maven教程

    eclipse使用maven教程eclipse使用maven教程什么是mavenmaven下载与安装与配置1下载2安装3配置环境变量在eclipse中配置1m2eclipse安装2配置eclipse3创建一个maven项目1项目的结构2Eclipse中maven常用的命3使用maven命令0.什么是maven参考https://www.cnblogs.com/whgk/p

    2022年4月6日
  • java中stringBuilder常用方法[通俗易懂]

    java中stringBuilder常用方法[通俗易懂]String对象是不可改变的。每次使用System.String类中的方法之一时,都要在内存中创建一个新的字符串对象,这就需要为该新对象分配新的空间。在需要对字符串执行重复修改的情况下,与创建新的String对象相关的系统开销可能会非常昂贵。如果要修改字符串而不创建新的对象,则可以使用System.Text.StringBuilder类。例如,当在一个循环中将许多字符串连接在一起时,使用StringBuilder类可以提升性能。通过用一个重载的构造函数方法初始化变量,可以创建StringBuild

    2022年7月17日
  • Pycharm精选插件

    Pycharm精选插件可能很多人都没有安装过什么pycharm插件,一个很重要的原因是默认的pycharm已经很强大了,已经有很多功能了,但是这不妨碍我们喜欢更强大的pycharm。下面介绍几款能够提高效率的插件MaterialThemeUI相信很多用过Sublime的同学,一装完pycharm的第一感觉就是:“怎么这么难看”,然后赶紧去找教程把主题换回Sublime主题。其实不用这么麻烦,只需要装了这个插…

    2022年6月24日

发表回复

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

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