🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #627

Re: Fill in IE forms

#627
From: Gizmo
Date: Sat, 27 May 2006 19:50
131 lines
5501 bytes
"BruBru" <bruno_scheirsen@hotmail.com> wrote:
>Hello all,
>
>Could anyone tell me how it is possible to fill in some fields in a web-form 
>(.htm) interacting with the web browser (IE 6). 
for sample...
first cut:
//on target page
...
WideString  wsName = "Name";
    CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2>                  pDoc;
    CComQIPtr<IHTMLElementCollection, &IID_IHTMLElementCollection>  pColl;
    CComQIPtr<IDispatch, &IID_IDispatch>                            pTmpDisp;
    CComQIPtr<IHTMLInputElement, &IID_IHTMLInputElement>            pElement1;
    CComQIPtr<IDispatch, &IID_IDispatch>                            pDisp1;
    CComQIPtr<IHTMLInputElement, &IID_IHTMLInputElement>            pElement2;
    CComQIPtr<IDispatch, &IID_IDispatch>                            pDisp2;
    
    if ( SUCCEEDED (WB->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pDoc)))
    {
        if ( SUCCEEDED (pDoc->get_all(&pColl)))
        {
            if ( SUCCEEDED (pColl->tags(TVariant("INPUT"), &pTmpDisp)))
            {
                pColl=pTmpDisp;
                TVariant v1("string"),  v12("Only"), v2;
                pColl->item( v1, v2, &pDisp1);
                pElement1 = pDisp1;
                pElement1->put_value(wsName);

                pColl->item( v12, v2, &pDisp2);
                pElement2 = pDisp2;
                pElement2->put_checked(1);

                // ������ �� ������ //click SUBMIT Button
                IHTMLElementCollection *HTMLForms = NULL;

                if ( SUCCEEDED ( pDoc->get_forms ( &HTMLForms ) ) && HTMLForms )
                {
                //  slHtmlFormName <form name=...>
                    TVariant vName5(0);
                    TVariant vIndex5;
                    IDispatch *pDisp5 = NULL;

                    if ( SUCCEEDED ( HTMLForms->item (vName5, vIndex5, &pDisp5 ) ) && pDisp5 )
                    {
                        IHTMLFormElement *HTMLForm = NULL;

                        if ( SUCCEEDED ( pDisp5 -> QueryInterface ( IID_IHTMLFormElement, ( LPVOID* )&HTMLForm ) ) && HTMLForm )
                        {
                            HTMLForm -> submit ();
                            HTMLForm -> Release ();
                        }

                        pDisp5 -> Release ();
                    }

                    HTMLForms -> Release ();
                }
            }
        }
    }

second cut:
void __fastcall TMyIEExtentionImpl::WIGetStat(String user)
{
    //TODO: Add your source code here
    //iieo?aiea noaoenoeee ?a?ac WinInet
    //http://ps.company.net/cgi-bin/status.pls
    // for POST
    // char *pTarget = "/cgi-bin/status.pls";
    // char *pOptHeaders = "user=gizmo";

    // for GET
    //char *pTarget = "/cgi-bin/status.pls?user=gizmo";
    //char *pOptHeaders = NULL;

    String Line, Msg;

    HINTERNET hInternet = InternetOpen("AGENT 007",
            INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    HINTERNET hConnection = InternetConnect(hInternet, "ps.company.net",
            80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

    HINTERNET hRequest = HttpOpenRequest(hConnection , "POST",
      "/cgi-bin/status.pls",
      NULL, NULL, NULL,
      INTERNET_FLAG_RELOAD | INTERNET_FLAG_DONT_CACHE, NULL);

    if(TRUE == ::HttpSendRequest( hRequest,
                              NULL,
                              0,
                              user.c_str(),
                              user.Length()))
    {
        //... You this not it is necessary ...
        DWORD dwRead;
        TCHAR szTemp[1024];
        while (InternetReadFile(hRequest, (LPVOID)szTemp, 1023, &dwRead))
        {
            if (!dwRead) break;
                szTemp[dwRead]='\0';

            Line = Line + String(szTemp);
        }
    }
    // close resource
    InternetCloseHandle(hRequest);
    InternetCloseHandle(hConnection);
    InternetCloseHandle(hInternet);
    // ... is it here found only for example ...
    int startpos = Line.Pos ( "<strong>" ) + AnsiString("<strong>").Length();
    int endpos   = Line.Pos ( "</strong>" );
    // ... oi?ie?oai niiauaiea ...
    Line = Line.SubString ( startpos, endpos-startpos );
    Msg.printf("Iauai iieo?aiiie eioi?iaoee:\n\r%s aaeo", Line.c_str());
    // ... iieo?aai HWND Browser-a ...
    HWND hBrowser=NULL;
	long lBrowser;
	if ( SUCCEEDED (m_pWebBrowser2->get_HWND(&lBrowser)))
        hBrowser=(HWND)lBrowser;

    MessageBox(hBrowser, Msg.c_str(), "Noaoenoeea gizmo", MB_OK);
}
...
WIGetStat(sPostData);

third:
http://bdn.borland.com/article/0,1410,27519,00.html
Technical Details
Message-ID: <4478ad6a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <44786e9d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,f300976b1ac80a22
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII
From: "Gizmo" <_gizmo@mail.ru>
Sender: "Gizmo" <_gizmo@mail.ru>
Reply-To: "Gizmo" <_gizmo@mail.ru>
Subject: Re: Fill in IE forms
Newsgroups: borland.public.cppbuilder.internet.web
X-User-Info: 195.201.33.13     
X-Forwarded-For: unknown
References:  <44786e9d$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4478ad6a$1@newsgroups.borland.com>
Date: 27 May 2006 12:50:02 -0700
X-Trace: newsgroups.borland.com 1148759402 207.105.83.66 (27 May 2006 12:50:02 -0700)
Lines: 131
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news2.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail