🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
1 messages
1 total messages Started by Mischa Simmonds Mon, 13 Aug 2007 13:51
Extracting all the HTMLElements from IHTMLDocument2 ?
#238
Author: Mischa Simmonds
Date: Mon, 13 Aug 2007 13:51
92 lines
4742 bytes
I am trying to get all the HTMLElements from IHTMLDocument2 via a 
IHTMLElementCollection that has been retrieved by All() (or in the case 
of C++, get_all(). The end result is that I am trying to access all the 
parameters of each element in the document eg: <INPUT type=hidden 
value=45533 name=Booking_No> so I can build a list containing all the 
name=value pairs.

Any ideas?


My existing C++ code which works so far in my application will geive me 
the URL, HTML, Text etc of the document....

         case DISPID_DOCUMENTCOMPLETE :                 
//DocumentComplete      DISPID( 259)
         {
            Shdocvw::tagREADYSTATE eREADYSTATE ;
            Server->Get_ReadyState( eREADYSTATE);
            if ( eREADYSTATE == Shdocvw::READYSTATE_COMPLETE) //  = 4
            {
                DelphiInterface<IHTMLDocument2> Doc = NULL;
                
if(SUCCEEDED(Server->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&Doc)))
                {
                    WideString wsHTML;
                    WideString wsOuterHTML;

                    WideString wsText;
                    WideString wsURL;
                    AnsiString asHTML;
                    AnsiString asText;
                    AnsiString asURL;

                    Doc->get_body(&body);
                    Doc->get_URL(&wsURL);
/*******************************************************************************************
*** BUT HERE IS MY LAME ATEMPT AT GETTING THE IHTMLElements from 
theIHTMLElementCollection ***
********************************************************************************************
                    DelphiInterface<IHTMLElementCollection> *collection;
                    Doc->get_all(&collection);
                    long p=collection->get_length(&p);
                    for(int i=0; i<p;i++)
                    {
                        element=collection-> item(i, '') as IHTMLElement;
                        DelphiInterface<IHTMLElement> element;
                        //plus I want to be able to extract the 
name/value pairs for each element
                    }
********************************************************************************************/
                    body->get_outerHTML(&wsHTML);
                    asHTML = wsHTML.Detach();
                    body->get_innerText(&wsText);
                    asText = wsText.Detach();
                    asURL = wsURL.Detach();


                    if(asHTML != "" && asURL!="")
                        if (FOnDocumentComplete) FOnDocumentComplete 
(asURL,asHTML,asText,body,Server);

                }
            }
         }


--------------------------------------------------------------------------------------------------------------------------------------------
This is an example of Delphi code I found on the web which looks close 
to be providing what I am looking for but I am unable to convert the 
Delphi to C++ in this instance...

procedure TForm.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
 var HTMLDocument: IHTMLDocument2;
     HTMLElementCollection: IHTMLElementCollection;
     HTMLElement: IHTMLElement;
     i: Integer;
begin
 HTMLDocument:=WebBrowser1.Document as IHTMLDocument2;
 if HTMLDocument= nil then
    raise Exception.Create('Couldn''t convert the ' +
      'FInternetExplorer.Document to an IHTMLDocument2');
  // First, grab all the elements on the web page
  HTMLElementCollection:=HTMLDocument.all;
  for i:=0 to HTMLElementCollection.length-1 do
  begin
    // Get the current element
    HtmlElement:=HTMLElementCollection.item(i, '') as IHTMLElement;
    // Add to my list of element
    .....
  end;
end
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads