Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the source of a page navigated by a webbrowser

Status
Not open for further replies.

Filterhead

Programmer
Aug 8, 2008
2
0
0
BE
I tried a lot of options but I don't seem to get it to work.

I actually just want to read a text file which is hosted somewhere and return the value as a string.

I found this code for Visual Basic:
Form1.browser.Document.documentElement.innerHTML

But there's no such option as documentElement in Document

Thanks for your time.

*Edit* Just found a neat code.

IHTMLDocument2* htm = NULL; // #include <mshtml.h>

AnsiString Source;

if(CppWebBrowser1->Document)
{
if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&htm)))
{
IPersistStreamInit* spPsi = NULL; // ocidl.h
if(SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&spPsi)) && spPsi)
{
IStream *spStream = NULL; // objidl.h
OleCheck(CreateStreamOnHGlobal(NULL, true, &spStream));
if(spStream)
{
__int64 nSize = 0;
STATSTG ss;
LARGE_INTEGER nMove;
nMove.QuadPart = 0;

OleCheck(spPsi->Save(spStream, true));
OleCheck(spStream->Seek(nMove, STREAM_SEEK_SET, (ULARGE_INTEGER*)&nSize));
OleCheck(spStream->Stat(&ss, STATFLAG_NONAME));

nSize = ss.cbSize.QuadPart;

Source.SetLength(nSize);
OleCheck(spStream->Read((void *)Source.data(), nSize, (ULONG*)&nSize));
OleCheck(spStream->Release());
}
spPsi->Release();
}
htm->Release();
}
}

MemoResults->Lines->Add(Source);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top