01 CComPtr<IDispatch> pDisp; 02 HRESULT hr = m_spWebBrowser->get_Document(&pDisp); 03 if (FAILED(hr)) 04 return hr; 05 06 // 确保我们取得的是一个IHTMLDocument2接口指针 07 // 让我们查询一下 IHTMLDocument2 接口 (使用灵敏指针) 08 CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML; 09 spHTML = pDisp; 10 11 // 抽取文档源代码 12 if (spHTML) 13 { 14 //获取文档内容并处理 15 } 16 else 17 { 18 //不是HTML文档 19 }