MFC / C++로 특정 사이트 가져와서 분석 하기 소스

#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <string>
#include <comdef.h>
#include <mshtml.h> 

#import <mshtml.tlb> no_auto_exclude 

#pragma comment(lib, "wininet.lib")

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char* argv[]){
	CoInitialize(NULL);

	ofstream dbfile ("output.db");
	string sLI;
	string m_strURL;
	HINTERNET hOpen, hFile;

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

	SAFEARRAY* psa = SafeArrayCreateVector(VT_VARIANT, 0, 1);
	VARIANT *param;

	hOpen = InternetOpen("UN/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

	hFile = InternetOpenUrl(hOpen, "http://online.wsj.com/public/page/news-global-world.html", NULL, 0, 0, 0);

	if(hFile){
		CHAR buffer[10*1024];
		DWORD dwRead;

		while(InternetReadFile(hFile, buffer, 1024, &dwRead)){
			if(dwRead == 0)
				break;

			buffer[dwRead] = 0;

			bstr_t bsData = (LPCTSTR)buffer;
			hr =  SafeArrayAccessData(psa, (LPVOID*)&param);
			param->vt = VT_BSTR;
			param->bstrVal = (BSTR)bsData;

			cout << buffer << endl;
			dbfile << buffer << endl;

			hr = pDoc->write(psa);

		} //end while loop

		hr = pDoc->close();
		InternetCloseHandle(hFile);
		SafeArrayDestroy(psa);
	}

	InternetCloseHandle(hOpen);
	dbfile.close();

	CoUninitialize();
	return 1;
}