🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Getting image from web site

#62
From: Hans Galema
Date: Fri, 16 Mar 2007 10:45
102 lines
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();
      }
}
Technical Details
Message-ID: <45fa760d$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.germany.com!newsfeed.datemas.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail
References: <45fa4d3d@newsgroups.borland.com> <45fa65c8@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,f9f39b263073b0ab
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Fri, 16 Mar 2007 11:45:04 +0100
From: Hans Galema <notused@notused.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.web
Subject: Re: Getting image from web site
References: <45fa4d3d@newsgroups.borland.com> <45fa65c8@newsgroups.borland.com>
In-Reply-To: <45fa65c8@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 145.98.201.248
Message-ID: <45fa760d$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1174042125 145.98.201.248 (16 Mar 2007 03:48:45 -0800)
Lines: 102
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.germany.com!newsfeed.datemas.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!newsfeed.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail