求教各位牛人IHTMLDocument2获取内嵌框架问题

 我来答
逆长小白菜
2016-01-28 · TA获得超过2万个赞
知道大有可为答主
回答量:1.7万
采纳率:94%
帮助的人:7819万
展开全部
已经解决了:
CString CTestDlg::ParseElementFromResponse(CString strResponse)
{
CString strRet("");
//declare our MSHTML variables and create a document
MSHTML::IHTMLDocument2Ptr pDoc;
MSHTML::IHTMLDocument3Ptr pDoc3;
MSHTML::IHTMLElementCollectionPtr pCollection;
MSHTML::IHTMLElementPtr pElement;

HRESULT hr = CoCreateInstance(CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER, IID_IHTMLDocument2, (void**)&pDoc);

//put the code into SAFEARRAY and write it into document
SAFEARRAY* psa = SafeArrayCreateVector(VT_VARIANT, 0, 1);
VARIANT *param;
bstr_t bsData = (LPCTSTR)strResponse;
hr = SafeArrayAccessData(psa, (LPVOID*)¶m);
param->vt = VT_BSTR;
param->bstrVal = (BSTR)bsData;

hr = pDoc->write(psa);
hr = pDoc->close();

SafeArrayDestroy(psa);

//I'll use IHTMLDocument3 to retrieve tags. Note it is available only in IE5+
//If you don't want to use it, u can just run through all tags in HTML
//(IHTMLDocument2->all property)
pDoc3 = pDoc;

//display HREF parameter of every link (A tag) in ListBox
pCollection = pDoc3->getElementsByTagName(L"input");
for(long i=0; i<pCollection->length; i++)
{
pElement = pCollection->item(i, (long)0);
if(pElement != NULL)
{
//second parameter says that you want to get text inside attribute as is
strRet += (LPCTSTR)bstr_t(pElement->getAttribute("name", 2));
strRet += "=";
strRet += (LPCTSTR)bstr_t(pElement->getAttribute("value", 2));
strRet += ";";
}
}

return strRet;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式