描述:
IHTMLDocument2 * pDoc = (IHTMLDocument2 *)(m_ie.GetDocument());
BSTR str;
IHTMLElement * pElement = NULL;
pDoc->get_body(&pElement);
pElement->get_outerText(&str);
//.......
我原意是要用过IE控件来Post表单数据,然后将服务器返回的数据得到,
但是返回的数据不是HTML的代码,而是一些XML文本,或者其他的数据
使用get_outerText不能获取接受到的全部文本,只能获取到其中XML元素的值,
改成使用get_outerHTML 时就会程序就崩溃,
请问这个问题如何解决?
谢谢
解决方案1:
1 每一步COM操作都需要判断结果是否失败
2 参考http://community.csdn.net/Expert/topicview.asp?id=783799
Browser Helper Objects: The Browser the Way You Want It
Dino Esposito
Microsoft Corporation
January 1999
HRESULT CViewSource::GetDocumentContent()
{
USES_CONVERSION;
// Get the WebBrowser's document object
CComPtr<IDispatch> pDisp;
HRESULT hr = m_spWebBrowser2->get_Document(&pDisp);
if (FAILED(hr))
return hr;
// Verify that what we get is a pointer to a IHTMLDocument2
// interface. To be sure, let's query for
// the IHTMLDocument2 interface (through smart pointers)
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML;
spHTML = pDisp;
// Extract the source code of the document
if (spHTML)
{
// Get the BODY object
hr = spHTML->get_body(&m_pBody);
if (FAILED(hr))
return hr;
// Get the HTML text
BSTR bstrHTMLText;
hr = m_pBody->get_outerHTML(&bstrHTMLText);
if (FAILED(hr))
return hr;
return S_OK;
}
//这里需要documentcomplete
2。得到返回值可以不用IHtmlDocument2,直接用wininet SendRequest方法
您可能想查找下面的文章:
- 为什么获取的IHTMLDocument2指针不能用
- 网页里有一个封装好的htc控件,该控件中有一些input输入框,我能不能通过IHTMLDocument2指针获取htc控件中的这些输入框内容
- 为什么在可编辑模式下的IHTMLDocument2接口取不到子element?
- 用IHTMLDocument2::execCommand的saveas将一个html文件保存为txt执行,为什么不行?
- 如何得到IID_IHTMLDocument2的指针呢?
- 在IE点击弹出一个新的窗口页面,如何获得这个页面的IHTMLDocument2?
- IHTMLDocument2,IHTMLElement如何释放?
- IHTMLDocument::getElementByName函数的问题。
- 100分请教个IHTMLDocument2问题
- 通过IHTMLDocument2接口只能得到body源码,有设呢方法可以到的head的源码?