前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mshtml一些用法

mshtml一些用法

作者头像
全栈程序员站长
发布2022-07-25 08:40:09
2650
发布2022-07-25 08:40:09
举报
文章被收录于专栏:全栈程序员必看

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

获取某个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.cn/127038.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年4月8,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档