怎么用IHTMLDocument2接口获取<span class="EX">*****</span>的数据啊
如题,我不知道怎么解决
[解决办法]
Using the Document Interface
[解决办法]
1. 用 IHTMLDocument2::all 获得所有元素;
2. 用 IHTMLElementCollection::tags 获得标签为 span 的元素;
3. 用 IHTMLElement::className 获得 class 名为 EX 的元素;
4. 用 IHTMLElement::innerText 获得文本。
[解决办法]
NHtm::GetSpanElement(pDocument, &pElement, "EX", NULL);
pElement->get_innerHTML(bStrText.GetAddress());
- C/C++ code
BOOL NHtm::GetSpanElement(IHTMLDocument2 *pDocument, IHTMLElement **ppElement, CHAR *pClassName, CHAR *pSpanId){ IHTMLElementCollection * pAllElem = NULL; IHTMLElement * pElement = NULL; IDispatch * pElemDisp = NULL; HRESULT hr = S_FALSE; BOOL bRetVal = FALSE; int i; _bstr_t bStrTagName; _bstr_t bStrClassName; _bstr_t bStrSpanId; LONG lCount; _variant_t ElemName; _variant_t ElemIndex; *ppElement = NULL; if(pDocument == NULL) return FALSE; hr = pDocument->get_all(&pAllElem); if(FAILED(hr) || pAllElem == NULL) return FALSE; hr = pAllElem->get_length(&lCount); if(FAILED(hr)) goto Done; for(i=0; i<lCount; i++) { ElemName = i; ElemIndex = i; hr = pAllElem->item(ElemName, ElemIndex, &pElemDisp); if(FAILED(hr) || pElemDisp == NULL) goto Done; hr = pElemDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement); if(FAILED(hr)) goto Done; hr = pElement->get_tagName(bStrTagName.GetAddress()); if(FAILED(hr)) goto Done; if(stricmp(bStrTagName, "SPAN") != 0) goto DoNext; if(pClassName) { hr = pElement->get_className(bStrClassName.GetAddress()); if(FAILED(hr)) goto Done; if(bStrClassName.length() == 0) goto DoNext; if(stricmp(bStrClassName, pClassName) != 0) goto DoNext; } if(pSpanId) { hr = pElement->get_id(bStrSpanId.GetAddress()); if(FAILED(hr)) goto Done; if(bStrSpanId.length() == 0) goto DoNext; if(stricmp(bStrSpanId, pSpanId) != 0) goto DoNext; } break;DoNext: if(pElemDisp) pElemDisp->Release(); if(pElement) pElement->Release(); } *ppElement = pElement; bRetVal = TRUE;Done: if(pAllElem) pAllElem->Release(); if(pElemDisp) pElemDisp->Release(); return bRetVal;}