Re: How to download web page with image?



ddeng722@xxxxxxxxx wrote:
Hello, I'm developing web robot that crawl web page.
bye the way, one thing driving me crazy is to find out how to download
web page with image like 'save as' of explorer.
when we click the menu named 'save as' of explorer, html and image
files might be downloaded in the folder.
so actually, if you know about component or COM or kinda solution, let
me know.
and ... I'm programming on '.NET' with 'c#'.

Thank you for reading this.


Here is a C++ Builder code that I use in my utility that downloads images from the Astronomy Picture of the day site for me.

The 'wb' variable is the IE ActiveX control that I host on my form.

Hope it helps:

void TForm1::GetImage()
{
if ( !oldFile.IsEmpty() )
DeleteFile( oldFile );
oldFile.SetLength( 0 );

IHTMLDocument2Ptr &doc = wb;
if ( doc ) {

// holds file name
String name;

try {
IDispatchPtr disp;
TVariant idx( 0 );
doc->images->item( idx, TNoParam(), &disp );


if ( disp ) {
IHTMLImgElementPtr img = disp;

if ( img ) {
IHTMLElementPtr parent = disp;
IHTMLAnchorElementPtr link = parent->parentElement;

if ( link ) {
char path [MAX_PATH];
char file [MAX_PATH];
GetTempPath( sizeof( path ), path );

if ( GetTempFileName( path, "img", 0, file ) ) {
name = file;
name += ".jpg";
// delete the temp file windows created for us
DeleteFile( file );

// get our image file
URLDownloadToFile( 0, AnsiString( link->href ).c_str(), name.c_str(), 0, 0 );
memo->Lines->Add( link->href );

std::auto_ptr <TJPEGImage> jpg(new TJPEGImage);
jpg->LoadFromFile( name );

// no need to keep the downloaded image around
DeleteFile( name );
name.SetLength( 0 );

name = file;
name += ".bmp";

std::auto_ptr <Graphics::TBitmap> bitmap( new Graphics::TBitmap );
if ( jpg->Width > Screen->Width && jpg->Height > Screen->Height ) {
bitmap->Width = Screen->Width;
bitmap->Height = Screen->Height;
TRect r( 0, 0, Screen->Width, Screen->Height );
bitmap->Canvas->StretchDraw( r, jpg.get() );
} else
bitmap->Assign( jpg.get() );

bitmap->SaveToFile( name );

oldFile = name;

if ( !SystemParametersInfo( SPI_SETDESKWALLPAPER, 0,
name.c_str(), SPIF_UPDATEINIFILE ) ) {
memo->Lines->Add( String( "Error is " ) + GetLastError() );
} else {
tray->BalloonHint = String( "Got new image - " ) + last.CurrentDate() +
String( ". Next update at " ) + TDateTime( last + 1 ).DateTimeString();
tray->Hint = String( "Next update at " ) + (last + 1 + TDateTime::CurrentTime() ).DateTimeString();
tray->ShowBalloonHint();
}
}
}
}
}
}
catch( ... ) {
if ( !name.IsEmpty() )
DeleteFile( name );
}
}
}

.



Relevant Pages

  • Re: Browser freeze
    ... IMHO) will graphically show you what network traffic is present on your system. ... Process Explorer will show you what processes, foreground and background, ... They're all free - and most pretty small, so they download quickly enough. ... Now check for, and remove, spyware. ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: cleaning out stuff on computer
    ... contained in Windows Explorer?.. ... open Internet Explorer 6 and then click on ... >> Mike Hall ... >>> Is there a program or place i can download a tool or something toteach ...
    (microsoft.public.windowsupdate)
  • Re: download nature songs to desktop
    ... MS MVP Windows - Internet Explorer ... automatically downloaded to my temporary internet files folder. ... My goal is to be able to download these files and ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: downloaded files say in properties Blocked
    ... >> Explorer to download files, ... when you want to clean out all the streams in files in a folder ... command prompt completely) and in Explorer locate the folder you want ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Internet Explorer 6 crash, reinstalled 6 but still not working
    ... From Control Panel> Internet Options> Advanced> uncheck "Enable third ... Download Toolbar Cop from http://www.majorgeeks.com/download4126.html ... windows explorer all worked fine. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)