Exalted Perl Monk Wizards: Goal: Navigate to a website using Win32::OLE, and save the results as a Web Archive - .MHT file in a directory and file name I choose programmatically, without prompting the user. The sample code below does not do the job. I am wondering what the proper mechanics are to accomplish this with Perl and the existing CPAN libraries
use Win32::OLE 'EVENTS'; use File::Spec::Functions; use File::Basename; $Win32::OLE::Warn = 3; $URL = "http://www.weather.com"; 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(); } $Contents = $IE->{DOCUMENT}; $Target = "g:\\zbuzz\\Weather.mht"; # # remove any prior file # $path = $Target; (my $filename = $path) =~ s/^.*[\\\/]//; # get just the filename po +rtion of path print "file=$filename\n"; $Targetdir= dirname($path); $currdir = Win32::GetCwd(); print "Current Working Directory=$currdir\n"; print "Targetdir=$Targetdir\n"; chdir ($Targetdir); $path = $Targetdir . "\\" . $filename; ($name, $dir, $ext ) = fileparse ($path, '\..*' ); print "name=$name, dir=$dir, ext=$ext \n"; $base = basename($path); $dir= dirname($path); print "dir=$dir, base=$base\n" ; # # changes the location of the saved file to the desired drive and dire +ctory # $newdir = chdir ( $dir); Win32::SetCwd($newdir); # moves the file save to g:\zbuzz unlink ( $Target ); # # Save the MHT file using ExecWB # my $OLECMDID_SAVEAS = '4'; my $OLECMDEXECOPT_PROMPTUSER = '0'; my $OLECMDEXECOPT_DONTPROMPTUSER = '1'; # prompts for the Save As +dialog # 4 - 1 combination produces Save Webpage ( so you can save as MHT ) # 4 - 1 combination populates file name as Window Title # 4 - 1 combination does not save the file in the desired directory; # 4 - 1 comination => have to manually change the directory to the des +ired location # # ExecWB does pull up the Save As HTML dialog box, however, Don't Prom +pt User does not work # $IE->ExecWB('4', '1', $Contents, $Target ); $IE->Quit(); exit; P.S., Where do I find the various constants to incorporate such as OLE +CMDEXECOPT_DONTPROMPTUSER, etc.

In reply to Perl - ExecWB - SaveAs No Prompts 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.