오후 1:09 2003-01-06
조경민 (bro@shinbiro.com)
HTML 소스 얻기
===================================================================
그냥 얻기
WebFileDownload하면 된다.
INet의 함수 이용
CInternetSession 이용도 가능

브라우저를 이용

두번째 질문과 관련된 참조할만한 코드 스니펫이라면 아래와 같습니다.

스트림으로 받는 방법이죠.
IHTMLDocument2 * pDoc = NULL;
IDispatch * pDisp = NULL;
IPersistStreamInit * pInit = NULL;
IStream * pStream = NULL;
HRESULT hr = pWebBrowser->GetDocument(&pDisp);
if ( SUCCEEDED(hr) && pDisp )
{
    hr = pDisp->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pDoc);
    if ( SUCCEEDED(hr) && pDoc )
    {
        hr = pDoc->QueryInterface(IID_IPersistStreamInit, (void**)&pInit);
        if (SUCCEEDED(hr) && pInit )
        {
            hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream);
            if ( SUCCEEDED(hr) && pStream )
            {
                pInit->Save(pStream, FALSE);
            }
        }
    }
}

다른 방법이라면 body의 outerText 이용이죠.

void CHtmlViewer::OnDocumentComplete(LPCTSTR lpszUrl)
{
HRESULT hr;

LPDISPATCH doc = GetHtmlDocument();

// Invoke GetDocumentElement member directly via IDispatch of document
//
DISPPARAMS dispparams;
memset(&dispparams, 0, sizeof dispparams);
VARIANT* pvarResult = NULL;
VARIANT vaResult;
pvarResult = &vaResult;
doc->Invoke(
  0x433,
  IID_NULL,
  0,
  DISPATCH_PROPERTYGET,
  &dispparams,
  pvarResult,
  NULL,
  NULL);

if (vaResult.vt==VT_DISPATCH)
{
  LPDISPATCH pDisp = vaResult.pdispVal;
  // Get the element interface
  IHTMLElement* pElem = NULL;
  if (SUCCEEDED(hr = pDisp->QueryInterface( IID_IHTMLElement,
(LPVOID*)&pElem )))
  {
   BSTR str;
   _bstr_t strTag;
   pElem->get_tagName( &str );
   strTag = str;

   pElem->get_outerHTML( &str );
   strTag = str;
   ((CHtmlDoc *)GetDocument())->SetSourceHTML( this, strTag );
   pElem->Release();
  } // QI(IHTMLElement) pDisp->Release();
}
}

'KB > MFC/Win32' 카테고리의 다른 글

mshtml 메모리 릭 최소화하기  (0) 2004.03.19
HTML 스크립트 함수 ActiveX에서 호출하기  (0) 2004.03.19
MFC DLL Debug/Release 구분해서 하기  (0) 2004.03.19
DLL, LIB 잘 배포하기  (0) 2004.03.19
def 파일에 대해서  (0) 2004.03.19

+ Recent posts