Thread View: borland.public.cppbuilder.internet.web
7 messages
7 total messages
Started by Grumps
Fri, 16 Mar 2007 07:53
Getting image from web site
Author: Grumps
Date: Fri, 16 Mar 2007 07:53
Date: Fri, 16 Mar 2007 07:53
8 lines
1272 bytes
1272 bytes
Hi All I'm not really a C++ programmer, but I have dabbled with C++Builder 5 a bit. I'm trying to grab an image from a web site. I can open a browser using CppWebBrowser1->Navigate(URL); and this is fine. Firstly, how do I know when the page has completed, and second, how do you get the images from this page? Sorry if this has been asked a thousand times, but my C++ knowledge is somewhat lacking.
Re: Getting image from web site
Author: Graeme
Date: Fri, 16 Mar 2007 09:35
Date: Fri, 16 Mar 2007 09:35
12 lines
1708 bytes
1708 bytes
Grumps wrote: > Hi All > I'm not really a C++ programmer, but I have dabbled with C++Builder 5 > a bit. I'm trying to grab an image from a web site. > I can open a browser using CppWebBrowser1->Navigate(URL); and this is > fine. Firstly, how do I know when the page has completed, and second, > how do you get the images from this page? > Sorry if this has been asked a thousand times, but my C++ knowledge is > somewhat lacking. Ok. Got the page completed issue sorted using the OnDocumentComplete event. Just need to get the images from the page.
Re: Getting image from web site
Author: Hans Galema
Date: Fri, 16 Mar 2007 10:45
Date: Fri, 16 Mar 2007 10:45
102 lines
3964 bytes
3964 bytes
Graeme wrote:
> Just need to get the images from the page.
T(Cpp)WebBrowsr has a method to give you all the img's on that page.
From thereon you can get the url in the src="url".
Code below shows the amount of images and after that displays the
src url's. Only it does not. It does display the url for the first image
only.
Maybe you can get it to work properly. At the moment I have no time for it.
If you get it to work pleas post the code.
Hans.
void __fastcall TForm1::SpeedButton22Click(TObject *Sender)
{
AnsiString AllImages;
IHTMLDocument2 *HTMLDoc = NULL;
if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&HTMLDoc)))
{
IHTMLElementCollection *pAll = NULL;
if(SUCCEEDED(HTMLDoc->get_images(&pAll))) // mshtml.h
{
long collSize;
pAll->get_length(&collSize);
IDispatch* id;
VARIANT one;
for( int idx = 0; idx < collSize; idx++)
{
one.vt = VT_UINT;
one.lVal = idx;
VARIANT two = {0};
pAll->item(one,two,&id);
IHTMLElement* pElem = NULL;
id->QueryInterface( IID_IHTMLElement, (LPVOID*)&pElem );
BSTR bstr = NULL;
pElem->toString(&bstr);
AllImages += bstr;
AllImages += "\n";
}
ShowMessage ( "AllObjects for Images\n\n" + AllImages ); // shows you amount
long count = -1;
long length = 0;
pAll->get_length( &length);
// ShowMessage ( "length: " + AnsiString ( length ) );
TVariant name = NULL;
TVariant index = count;
IDispatch *pDisp = NULL;
while ( ++ count < 5) // 5!!
{
OleVariant varIndex((int)count);
// index = count;
pDisp = NULL;
if(SUCCEEDED(pAll->item(name, varIndex, &pDisp)))
// if(SUCCEEDED(pAll->item(name, index, &pDisp)))
//if(SUCCEEDED(pAll->item("",count, &pDisp)))
{
// ShowMessage ( "SUCCEEDED(pAll->item(name, index, &pDisp))) " + IntToStr ( (int)pDisp) );
if ( pDisp )
{
IHTMLImgElement *ImgElement = NULL; // mshtml.h
pDisp->QueryInterface(IID_IHTMLImgElement, (LPVOID*)&ImgElement);
pDisp->Release();
if(ImgElement)
{
WideString src;
ImgElement->get_src ( &src );
ShowMessage ( src) ;
SysFreeString (src);
ImgElement->Release();
}
}
}
else
break;
}
pAll->Release();
}
HTMLDoc->Release();
}
}
Re: Getting image from web site
Author: Grumps
Date: Fri, 16 Mar 2007 10:56
Date: Fri, 16 Mar 2007 10:56
26 lines
1787 bytes
1787 bytes
Hans Galema wrote:
> Graeme wrote:
>
>> Just need to get the images from the page.
>
> T(Cpp)WebBrowsr has a method to give you all the img's on that page.
>
> From thereon you can get the url in the src="url".
>
> Code below shows the amount of images and after that displays the
> src url's. Only it does not. It does display the url for the first
> image only.
>
> Maybe you can get it to work properly. At the moment I have no time
> for it. If you get it to work pleas post the code.
>
> Hans.
>
> void __fastcall TForm1::SpeedButton22Click(TObject *Sender)
> {
> AnsiString AllImages;
>
> IHTMLDocument2 *HTMLDoc = NULL;
I've fallen at the first hurdle!
Where do I get IHTMLDocument2 from? Is it part of C++Builder5?
Re: Getting image from web site
Author: Hans Galema
Date: Fri, 16 Mar 2007 11:42
Date: Fri, 16 Mar 2007 11:42
10 lines
1371 bytes
1371 bytes
Grumps wrote:
> I've fallen at the first hurdle!
> Where do I get IHTMLDocument2 from? Is it part of C++Builder5?
The comment should have given you the clue:
if(SUCCEEDED(HTMLDoc->get_images(&pAll))) // mshtml.h
Hans.
Re: Getting image from web site
Author: Grumps
Date: Fri, 16 Mar 2007 11:47
Date: Fri, 16 Mar 2007 11:47
11 lines
1330 bytes
1330 bytes
Hans Galema wrote: > Grumps wrote: > >> I've fallen at the first hurdle! >> Where do I get IHTMLDocument2 from? Is it part of C++Builder5? > > The comment should have given you the clue: > > if(SUCCEEDED(HTMLDoc->get_images(&pAll))) // mshtml.h Oops! It does now. Thanks.
Re: Getting image from web site
Author: Grumps
Date: Sun, 18 Mar 2007 08:23
Date: Sun, 18 Mar 2007 08:23
21 lines
1798 bytes
1798 bytes
"Hans Galema" <notused@notused.nl> wrote in message news:45fa760d$1@newsgroups.borland.com... > Graeme wrote: > >> Just need to get the images from the page. > > T(Cpp)WebBrowsr has a method to give you all the img's on that page. > > From thereon you can get the url in the src="url". > > Code below shows the amount of images and after that displays the > src url's. Only it does not. It does display the url for the first image > only. > > Maybe you can get it to work properly. At the moment I have no time for > it. > If you get it to work pleas post the code. I've looked at the code, but have absolutely no idea why it doesn't work. I've since found another code snippet that gets an image. In fact, there is only one image on the page I'm looking at, which makes it easy.
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