Thread View: borland.public.cppbuilder.internet.web
9 messages
9 total messages
Started by Saulo I. Regis
Wed, 03 Nov 2004 21:57
TCppWebBrowser and Framed HTML Pages
Author: Saulo I. Regis
Date: Wed, 03 Nov 2004 21:57
Date: Wed, 03 Nov 2004 21:57
79 lines
3567 bytes
3567 bytes
Hi,
I'm new to TCppWebBrowser and I'm having a hard time to figure out how to
get the complete HTML code of a framed homepage.
There is a homepage with those 3 traditional frames: a heading frame, a left
menu frame and a main frame that shows the real content of the web site.
I Navigate to the root URL of that homepage and after that I choose some
menu options that refreshes the contents of the main frame. When I reach the
desired content I'm trying to capture the HTML code of it.
To do this I'm using the following code (partial)
bool bDoc_Ok;
TComInterface<IHTMLDocument2> Doc;
bDoc_Ok = Browser1->Document;
if ( bDoc_Ok )
Browser1->Document->QueryInterface(IID_HTMLDocument2, (LPVOID*)&Doc);
if ( Doc )
{
TComInterface<IPersistStreamInit> Psi;
Doc->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&Psi);
if ( Psi )
{
OleCheck(Psi->Save(*Adapter, FALSE));
cHtml = StrStrm->DataString;
.
. do something with cHtml
.
}
}
when I execute this code with the TCppWebBrowser component fully loaded with
the desired content I'm receiving just the "root" html code of the homepage
that defines the FRAMESET structure of the page! Something like that
(partial)
<frameset rows="*" cols="154,*" frameborder="NO" border="0"
framespacing="0">
<frame name="leftFrame" scrolling="NO" noresize
src="principal/index/menu.htm">
<frameset rows="79,*" frameborder="NO" border="0" framespacing="0"
cols="*">
<frame name="topFrame" noresize scrolling="NO"
src="principal/index/top.htm">
<frame name="main" src="principal/main.htm">
</frameset>
</frameset>
The main problem is that the actual URL that is being shown in the "main"
frame is not more "principal/main.htm". This URL is the "root" URL that is
first opened in that frame when the root URL of the web site is accessed.
My questions are:
#1. Why TCppWebBrowser() is not retrieving the updated URL of the "main"
frame after I had Navigated thru that web site?
#2. As TCppWebBrowser() already downloaded all the html code of all frames
how can I access them without having to reload it (even if I had the updated
"main" frame URL)?
#3. The OnDocumentComplete event is fired after each frame is loaded (and
once more to acknowledge that the whole "page" is ready!). How can I
"capture" the html code of the received frame inside the OnDocumentComplete
event handler using the LPDISPATCH pDisp parameter?
Saulo
Re: TCppWebBrowser and Framed HTML Pages
Author: Remy Lebeau (TeamB)
Date: Wed, 03 Nov 2004 23:50
Date: Wed, 03 Nov 2004 23:50
18 lines
1737 bytes
1737 bytes
"Saulo I. Regis" <saulo@password.info> wrote in message news:418954e8@newsgroups.borland.com... > when I execute this code with the TCppWebBrowser component > fully loaded with the desired content I'm receiving just the "root" > html code of the homepage that defines the FRAMESET structure > of the page! That is because you are querying the HTML from the wrong Document object. You are not taking frames into account at all. IHTMLDocument2 has a frames collection in it. You are supposed to use that collection to get the IHTMLWindow2 interface for the desired frame, and then you can get the frame's IHTMLDocument2 interface from that. Then you can get the HTML that you are interested in from that. Gambit
Re: TCppWebBrowser and Framed HTML Pages
Author: Saulo I. Regis
Date: Thu, 04 Nov 2004 00:03
Date: Thu, 04 Nov 2004 00:03
15 lines
1561 bytes
1561 bytes
> That is because you are querying the HTML from the wrong Document object. > You are not taking frames into account at all. IHTMLDocument2 has a frames > collection in it. You are supposed to use that collection to get the > IHTMLWindow2 interface for the desired frame, and then you can get the > frame's IHTMLDocument2 interface from that. Then you can get the HTML that > you are interested in from that. Hi Remy, Could you give me a small sample code of how I access the frames collection, scan it and retrieve the HTML code of each frame? Saulo
Re: TCppWebBrowser and Framed HTML Pages
Author: Remy Lebeau (TeamB)
Date: Thu, 04 Nov 2004 01:06
Date: Thu, 04 Nov 2004 01:06
80 lines
3108 bytes
3108 bytes
"Saulo I. Regis" <saulo@password.info> wrote in message
news:418972c3$1@newsgroups.borland.com...
> Could you give me a small sample code of how I access
> the frames collection, scan it and retrieve the HTML code
> of each frame?
I take it that you did not read the documentation for IHTMLDocument2 yet,
did you?
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface.asp
#include <memory>
#include <utilcls.h>
void __fastcall GetFramesHTML()
{
if( !Browser1->Document ) return;
TComInterface<IHTMLDocument2> Doc;
Browser1->Document->QueryInterface(IID_HTMLDocument2,
(LPVOID*)&Doc);
if( !Doc ) return;
TComInterface<IHTMLFramesCollection2> Frames;
Doc->get_frames(&Frames);
if( !Frames ) return;
long cnt = 0;
Frames->get_length(&cnt);
for(long l = 0; l < cnt; ++l)
{
TVariant idx = l;
TVariant ret;
Frames->item(&idx, &ret);
if( (ret.vt != VT_DISPATCH) || (ret.pdispVal == NULL) )
continue;
TComInterface<IHTMLWindow2> Window;
ret.pdispVal->QueryInterface(IID_IHTMLWindow2,
(LPVOID*)&Window);
if( !Window ) continue;
TComInterface<IHTMLDocument2> Doc2;
Window->get_document(&Doc2);
if( !Doc2 ) continue;
AnsiString HTML = GetHTML(Doc2);
if( !HTML.IsEmpty() )
// use HTML as needed...
}
}
AnsiString __fastcall GetHTML(IHTMLDocument2* Doc)
{
if( Doc )
{
TComInterface<IPersistStreamInit> Psi;
Doc->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&Psi);
if( Psi )
{
std::auto_ptr<TStringStream> StrStrm(new TStringStream(""));
std::auto_ptr<TStreamAdapter> Adapter(new
TStreamAdapter(StrStrm.get(), soReference));
if( SUCCEEDED(Psi->Save(*Adapter, FALSE)) )
return StrStrm->DataString;
}
}
return "";
}
Gambit
Re: TCppWebBrowser and Framed HTML Pages
Author: Saulo I. Regis
Date: Thu, 04 Nov 2004 02:23
Date: Thu, 04 Nov 2004 02:23
26 lines
1836 bytes
1836 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> escreveu na mensagem news:4189803d$1@newsgroups.borland.com... > > I take it that you did not read the documentation for IHTMLDocument2 yet, > did you? Yep! I mean... nope :) I was digging the C++ Builder Help and things were very cryptic! > http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface .asp Wow man... "The Earth is Blue!" :) Thank you a lot for pointing out these docs to me! This is powerfull stuff! > #include <memory> > #include <utilcls.h> No words to express my gratitude to you on this code sample! #include <AllTheBestToYou> Saulo
Re: TCppWebBrowser and Framed HTML Pages
Author: Saulo I. Regis
Date: Thu, 04 Nov 2004 23:35
Date: Thu, 04 Nov 2004 23:35
58 lines
3027 bytes
3027 bytes
Hi Remy,
Your code seems to work great!
All frames are being retrieved BUT it fails to retrieve the current HTML
code of the "main" frame!
May be it has to do with its content and how to deal with it?
The "main" frame content starts with a link to a CSS file (see bellow)
***************************************
<title>estatisticas</title>
<link rel="stylesheet" href="index/styles.css" type="text/css">
<STYLE type=text/css>BODY {
CROLLBAR-ARROW-COLOR: #FFFFFF; SCROLLBAR-TRACK-COLOR: #9999cc;
SCROLLBAR-BASE-COLOR: #666699; scrollbar-dark-shadow-color: #765C47
}
</STYLE>
****************************************
Just after that a TABLE is defined and two FLASH MOVIES are inserted on the
first row with the html code bellow
******************************
<div align="center"><object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.ca
b#version=5,0,0,0" width="236" height="62" align="middle">
<param name=movie value="../imagens/banners/anuncie.swf">
<param name=quality value=high>
<embed src="../imagens/banners/anuncie.swf" quality=high
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_
Version=ShockwaveFlash" type="application/x-shockwave-flash" width="236"
height="62" align="middle">
</embed>
</object>
*******************************
and after that the content goes "normal" as texts inside the Table's cols
and rows!
I wonder if the existence of FLASH MOVIES would affect the way I need to
retrieve this HTML code using the OLE interfaces.
As I cannot predict the kind of web sites (and theirs contents) that will be
navigated and retrieved, may be it'll be better to just retrieve the URLs of
each frame content and use INDY to GET it?
Saulo
Re: TCppWebBrowser and Framed HTML Pages
Author: Remy Lebeau (TeamB)
Date: Fri, 05 Nov 2004 04:07
Date: Fri, 05 Nov 2004 04:07
33 lines
2135 bytes
2135 bytes
"Saulo I. Regis" <saulo@password.info> wrote in message news:418abe49@newsgroups.borland.com... > All frames are being retrieved BUT it fails to retrieve > the current HTML code of the "main" frame! Please show your actual code for accessing that frame. > May be it has to do with its content and how to deal with it? The HTML content does not effect IPersistStreamInit's ability to save the HTML. It is treated as raw data, and saved as-is. > I wonder if the existence of FLASH MOVIES would affect > the way I need to retrieve this HTML code using the OLE interfaces. No, it does not. > As I cannot predict the kind of web sites (and theirs contents) that will be > navigated and retrieved, may be it'll be better to just retrieve the URLs of > each frame content and use INDY to GET it? You could start by testing why the current code is failing to begin with. All interface methods return an HRESULT that contain an error code if something goes wrong. Your first step should be to track down which specific line is failing, and then checking to see which error code it is returning. Gambit
Re: TCppWebBrowser and Framed HTML Pages
Author: Saulo I. Regis
Date: Fri, 05 Nov 2004 04:24
Date: Fri, 05 Nov 2004 04:24
49 lines
3186 bytes
3186 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> escreveu na mensagem news:418afc51$1@newsgroups.borland.com... > Please show your actual code for accessing that frame. As here it's 2:30 a.m. and I had already turned off my dev computer I'll try to give you a quick answer now and a more complete today!! morning. The code is the same supplied by you in this thread. All frames are being retrieved in the same loop with the same code. One thing is that the "main" frame content has 127.79 kb! Is somewhat big because is a Table with over 3,000 lines! > > May be it has to do with its content and how to deal with it? > > The HTML content does not effect IPersistStreamInit's ability to save the > HTML. It is treated as raw data, and saved as-is. I read a post of june/2004 where you say the IE has some kind of security problems with CSS links but no specific directions were given in that thread! > You could start by testing why the current code is failing to begin with. > All interface methods return an HRESULT that contain an error code if > something goes wrong. Your first step should be to track down which > specific line is failing, and then checking to see which error code it is > returning. Yes. That is my preferred way because I don't want to retransmit content that the IE already received and is already inside the data area of the object! The first thing I'll do after wakening up 8-) ... is to check the HRESULT return codes and post the results here along with the actual code I'm using to retrieve the frames! Anyway I READ THE DOCS :) and I was able to retrieve the URL of each frame so I'm confident that at least the Indy way is at reach as a last resource! I tried to use the toString( ) method of IHTMLDocument but it only retrieves "[Object]" literal. Have nice dreams everybody :) Nite! Saulo
Re: TCppWebBrowser and Framed HTML Pages
Author: Remy Lebeau (TeamB)
Date: Fri, 05 Nov 2004 08:21
Date: Fri, 05 Nov 2004 08:21
17 lines
1770 bytes
1770 bytes
"Saulo I. Regis" <saulo@password.info> wrote in message news:418b0518@newsgroups.borland.com... > I read a post of june/2004 where you say the IE has some > kind of security problems with CSS links but no specific > directions were given in that thread! What I actually said in that discussion was not realted to CSS specificall. IE has security issues when accessing content across multiple servers. In other words, if you load a frameset from one website, and one of the frames loads content from a different website, then there are security issues with that. If everything is coming from the same website, though, then everything should be fine. Gambit
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