大家好,又见面了,我是你们的朋友全栈君。
获取某个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