Perl Wizards,

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 #

In reply to SaveAs in IE by Ad Aspera

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.