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


相关推荐

  • 如何为pycharm配置解释器_python解释器加入pycharm

    如何为pycharm配置解释器_python解释器加入pycharm我们需要提前下载好python解释器解释器可以在Python解释器官网下载,这里我下载的是3.8.8版本的1、在我们安装好pycharm的时候,并不是直接可以用的,我们还需要配置解释器,不配置解释器的话,就会出现下面这种情况。此时,小伙伴们莫慌,只要我们配置好解释器就可以了。2、首先点击上图中“ConfigurePythonInterpreter”,之后Pycharm就会自动定位到“ProjectInterpreter”这个位置,如下图所示,该界面是Pycharm的设置窗口之一,专门用

    2022年8月26日
    8
  • jquery插件treetable 动态加载问题

    jquery插件treetable 动态加载问题使用jquery插件treetable增加后刷新table时,树形样式丢失在增加或修改后,动态加载html,开始就直接使用$(“#treeTabletbody”).empty().append(data);这个用法是错误的,后来换成//成功后刷新表格 $(“#treeTabletbody”).empty();varhtml=data.htmlTable;…

    2022年5月27日
    130
  • 数据库系列之TiDB存储引擎TiKV实现机制

    数据库系列之TiDB存储引擎TiKV实现机制TiDB存储引擎TiKV是基于RocksDB存储引擎,通过Raft分布式算法保证数据一致性。本文详细介绍了TiKV存储引擎的实现机制和原理,加深对TiDB底层存储架构的理解。

    2022年9月23日
    4
  • (转载)详细设计-盒图 PAD图 过程设计语言

    (转载)详细设计-盒图 PAD图 过程设计语言(转载)详细设计-盒图PAD图过程设计语言1、详细设计的任务(主要工作)有哪些?详细设计的工作:确定应该怎样具体地实现所有要求的系统,也就是说经过这个阶段的设计工作,应该得出目标系统的精确描述。设计得到的结果是确定每个模块内部的算法和数据结构,产生描述各模块处理过程的详细文档。2、软件详细设计描述工具的概念和使用:程序流程图、N-S图、PAD图、PDL语言:什么是,基本符号和表…

    2022年8月13日
    9
  • shiro的面试题_综合分析面试题

    shiro的面试题_综合分析面试题Shiro框架介绍shiro安全数据源有哪些:Shiro运行流程Shiro的优点比较SpringSecurity和Shiro简述Shiro的3个核心组件 1.Subject 2.SecurityManager 3.RealmsShiro认证过程Shiro授权过程Shiro如何自实现认证如何实现自实现授权如何配置在Spring中配置使用Shiro

    2022年10月14日
    2
  • apache 负载均衡策略_dubbo有哪几种负载均衡策略

    apache 负载均衡策略_dubbo有哪几种负载均衡策略将Apache作为LoadBalance前置机分别有三种不同的部署方式,分别是:1)轮询均衡策略的配置进入Apache的conf目录,打开httpd.conf文件,在文件的末尾加入:ProxyPass/balancer://proxy/        #注意这里以”/”结尾balancer://proxy>        BalancerMemberhttp:

    2022年10月10日
    2

发表回复

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

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