CppWebBrowser 操作DIV里的内容.
我想把DIV里的内容替换掉,但是下面的这段程序遍历不到 DIV,只能遍历到页面控件,怎么解决呢.
if(SUCCEEDED(spDispatch->QueryInterface(IID_IHTMLElement,(void**)&pElement))){BSTR text1;pElement->get_id(&text1)ShowMessage(text1);}
修改一下,应该就可以用了。//---------------------------------------void __fastcall GetHtmlSource(LPDISPATCH WebDoc,AnsiString &strHtmlSource){ //TODO:取得WebDoc中的所有的源代码。 IDispatch *pDispatch=NULL; IHTMLDocument3 *pDocument3=NULL; IHTMLElementCollection *pElementCollection=NULL; IHTMLElement *pElement=NULL; if(SUCCEEDED(WebDoc->QueryInterface(IID_IHTMLDocument3, (LPVOID*)&pDocument3))) { if(SUCCEEDED(pDocument3->getElementsByTagName(L"HTML", &pElementCollection))) { Variant varName; Variant varIndex=0; if(SUCCEEDED(pElementCollection->item(varName, varIndex, &pDispatch))) { if(SUCCEEDED(pDispatch->QueryInterface(IID_IHTMLElement, (LPVOID*)&pElement))) { BSTR bstrHTML; pElement->get_outerHTML(&bstrHTML); Variant varHTML=bstrHTML; strHtmlSource = VarToStr(varHTML); SysFreeString(bstrHTML); pElement->Release(); } pDispatch->Release(); } pElementCollection->Release(); } pDocument3->Release(); }}//---------------------------------------