天天看点

取得WebBrowser网页内容

一、假定

1、已创建了一个WebBrowser对象为m_m_RegFormBrowser

2、包含了头文件

#include <MsHtmcid.h>

#include <mshtmdid.h>

#include <mshtml.h>

3、加载了网页/页面

m_RegFormBrowser.Navigate(m_homePage,&noarg,

        &noarg,&noarg,

        &noarg);

二、要做的事情

网页加载完后,获得文档内容以便后继处理.代码如下,慢慢看,呵呵

  CString strBody;

  IHTMLDocument2 * pHtmlDoc2=(IHTMLDocument2*)m_RegFormBrowser.GetDocument();

  if(pHtmlDoc2)

  {

   HRESULT hr = S_OK;

   IHTMLElement *pBodyElement;

   hr=pHtmlDoc2->get_body( &pBodyElement); 

   ASSERT(hr==S_OK);

   BSTR pbBody;

   hr=pBodyElement->get_innerText(&pbBody);

   ASSERT(hr==S_OK);

   //转化为CString

   strBody=_com_util::ConvertBSTRToString(pbBody);

   //ASSERT(strBody.IsEmpty());

   TRACE(strBody);

   m_UID=GetUIN(strBody);//应用,你就不要问这是什么了。

   TRACE(m_UID);

   pBodyElement->Release();

  }

三、小结

其实很简单。

继续阅读