Ad Aspera has asked for the wisdom of the Perl Monks concerning the following question:
I want to perform an unprompted SaveAs using OLE to save a web page.
In particular,
I want to save some files as
=> HTML - such as you would get with a "View Source" from IE
=> MHT - saving some files as a web archive such as you would get
if doing a
- File
- Save As from IE's menu
The script below will produce the Save As HTML dialog box. It is 'prompted" and only offers an HTML or Text option.
This demonstrates what happens with => ExecWB
I get comparable results with
=> Execcmd('SaveAs' ....
I apparently don't understand the proper magic.
Please comment on what I've missed.
# ============================================= use Win32::OLE 'EVENTS'; $Win32::OLE::Warn = 3; # # command line argument => URL to get # usage: perl OLE_SaveAs.pl http://132620.yourkwagent.com/home # (substitute your URL here to test) $URL = $ARGV[0]; my $IE = Win32::OLE->new("InternetExplorer.Application") || die "Could not start Internet Explorer\n"; $IE->{Addressbar} = 1; $IE->{Menubar} = 1; $IE->{Toolbar} = 1; $IE->{Statusbar} = 1; $IE->{Width} = 800; $IE->{Height} = 700; $IE->{Top} = 0; $IE->{Left} = 0; $IE->{Resizable} = 1; $IE->{visible} = 1; # Navigate to desired URL $IE->Navigate($URL); while ($IE->{Busy}) { Win32::Sleep 500; Win32::OLE->SpinMessageLoop(); } $Target = "g:\\zbuzz\\LeeMarlin.htm"; # # remove any prior file # unlink ( $Target ); # # Save the HTML file using ExecWB # my $OLECMDID_SAVEAS = '4'; my $OLECMDEXECOPT_DONTPROMPTUSER = '2'; # # ExecWB does pull up the Save As HTML dialog box, however, Don't Prompt User does not work # $IE->ExecWB($OLECMDID_SAVEAS, $OLECMDEXECOPT_DONTPROMPTUSER, $Target); # Quit IE $IE->Quit(); exit; # =============================================================== # Note: I've tried this alternative too, with similar results # # $IE = Navigate ($URL); # $IEDocument = $IE->{Document}; # $IEDocument->execCommand("SaveAs", "2", $Target ); # P.S., # Want to save some files as # HTML - such as you would get with a "View Source" from IE # MHT - saving some files as a web archive such as you would get if doing a # File # - Save As from IE's menu #
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SaveAs in IE
by CountZero (Bishop) on Jul 23, 2005 at 20:23 UTC | |
|
Re: SaveAs in IE
by silent11 (Vicar) on Jul 24, 2005 at 06:10 UTC | |
|
Re: SaveAs in IE
by puploki (Hermit) on Jul 24, 2005 at 20:43 UTC | |
|
Re: SaveAs in IE
by clscott (Friar) on Jul 25, 2005 at 02:26 UTC |