TCppWebBrowser - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

TCppWebBrowser

enridpenridp Posts: 4Member
Hello ! I'll try to be brief and easy-to-follow ("I'll try" because I'm not very good speaking/writing in english)
My problem: I'm using the TCppWebBrowser component (C++ Builder 5) and I don't know how to view the source code of the webpage.
I have checked all the properties and methods but I didn't find anything to do this.
I see the NMHTTP component too (FastNet palette), and, although it gives me the source code (even the cookies and header), I can't visualize the

webpage with it (additionally the NMHTTP component has a problem with redirections...)
And since many webpages change in each visit, I can't use the NMHTTP component AND AFTER TCppWebBrowser.
I hope somebody helps me to do this..
Thanks !
Enrique.

Comments

  • VampireFEVampireFE Posts: 36Member
    : Hello ! I'll try to be brief and easy-to-follow ("I'll try" because I'm not very good speaking/writing in english)
    : My problem: I'm using the TCppWebBrowser component (C++ Builder 5) and I don't know how to view the source code of the webpage.
    : I have checked all the properties and methods but I didn't find anything to do this.
    : I see the NMHTTP component too (FastNet palette), and, although it gives me the source code (even the cookies and header), I can't visualize the
    :
    : webpage with it (additionally the NMHTTP component has a problem with redirections...)
    : And since many webpages change in each visit, I can't use the NMHTTP component AND AFTER TCppWebBrowser.
    : I hope somebody helps me to do this..
    : Thanks !
    : Enrique.
    :

    Hey! Here, I was looking for the same some time ago. I found the way to get html source, I don't understand much of it though. But I managed to make this:

    void GetPageSource(TCppWebBrowser *CppWB,AnsiString *PageSource)
    {
    AnsiString pSource;
    TVariant v2;
    IHTMLDocument2 *htm = NULL; // #include

    if(CppWB->Document && SUCCEEDED(CppWB->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;
    pSource.SetLength(nSize);
    OleCheck(spStream->Read((void *)pSource.data(), nSize, (ULONG*)&nSize));
    OleCheck(spStream->Release());
    }
    spPsi->Release();
    }
    htm->Release();
    }
    PageSource->SetLength(pSource.Length());
    *PageSource=pSource;
    }

    You give it pointer to your cpp web browser and pointer to AnsiString where you want to save page source. It worked for me. Hope it helps.
Sign In or Register to comment.