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


相关推荐

  • getparameter方法的作用_have got和have的区别

    getparameter方法的作用_have got和have的区别getParameter和getAttribute区别(超详细分析)对getParameter过程,如下图:对getAttribute过程,如下图:两者区别:①getParameter()获取的是客户端设置的数据。getAttribute()获取的是服务器设置的数据。②getParameter()永远返回字符串getAttribute()返…

    2022年10月24日
    0
  • Xray的快速使用

    Xray的快速使用快速使用使用基础爬虫爬取并扫描整个网站xraywebscan–basic-crawlerhttp://example.com–html-outputcrawler.html使用HTTP代理进行被动扫描xraywebscan–listen127.0.0.1:7777–html-outputproxy.html设置浏览器http代理为http://127.0.0.1:7777,就可以自动分析代理流量并扫描。如需扫描https流量,请阅读下方文档抓取htt

    2022年5月30日
    66
  • 记一次固态硬盘数据恢复

    记一次固态硬盘数据恢复背景15年初的时候买过一个128G的固态硬盘,在自己的笔记本电脑上组了一个双硬盘(ssd+hdd),ssd作为系统盘。到今年也已经用了三年了。昨天上午的时候,电脑突然蓝屏报错,本来以为是一次简单的蓝屏故障,但是发现电脑重启之后,电脑报错找不到硬盘。当时心里一凉,难道硬盘寿终就寝了,但是硬盘坏了不重要,里面的数据还没有备份会比较可怕。赶快用一个winpe系统把电脑开起来,想看看数据是否还在。然…

    2022年9月20日
    0
  • Html —— JavaScript全局变量问题

    Html —— JavaScript全局变量问题问题在项目开发中发现在使用不同位置的相同接口时,入参相同。解决在JavaScript中声明变量如果不写”let”,将声明为全局变量,即页面所有该名称数据保持一致。在声明变量时,前面加上”let”即可。//全局变量abc=”123″//局部变量letabc=”123″…

    2022年6月11日
    29
  • Petshop4 的研究分析「建议收藏」

    Petshop4 的研究分析「建议收藏」 1.项目概述与架构分析微软刚推出了基于ASP.NET2.0下的PetShop4,该版本有了一个全新的用户界面。是研究ASP.NET2.0的好范例啊,大家都知道,一直以来,在.NET和Java之间争论不休,到底使用哪个平台开发的企业级应用性能最好、结构最优、生产力最高。为了用事实说话,通过对项目各方面的性能评估进而在比较.NET和Java的高下。用户做比较的这个项目就是Petshop

    2022年10月16日
    0
  • 各种加解密算法比較

    各种加解密算法比較

    2021年12月5日
    44

发表回复

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

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