1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#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*)¶m);
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;
}
| |