So you have written code to automate a website, but at a certain point you want to actually use the website your self - for example, a script logs you in. This snippet shows you how to do a handoff of the HTML to Internet Explorer, even with working relative links. The only problem that remains is cookies - these could propably be installed via some injected JavaScript code, but I haven't given that much thought. If Mozilla has anything comparable, I'd like to hear about it - I really like this method of debugging my web automation scripts.
use strict; use Win32::OLE; { my $browser; sub browser { unless ($browser) { $browser = Win32::OLE->CreateObject("InternetExplorer.Applicatio +n"); $browser->{'Visible'} = 1; $browser->Navigate('about:blank'); }; $browser; }; }; sub handoff { my ($uri,$html) = @_; my $document = browser->{Document}; $document->open("text/html","replace"); # If there is no <BASE> tag, set one. $html =~ s!(</head>)!<base href="$uri" />$1!i unless ($html =~ /<BASE/i); $document->write($html); }; my $html = <<HTML; <html><head></head><body> <!-- Note the relative image path here ! --> <img src="images/hp0.gif"><img src="images/hp1.gif"><img src="images/h +p2.gif"><br /> <form action="/search" name=f> <input maxLength=256 size=55 name=q value=""> <input type=submit value="Go Go Go" name=btnG> </form> </body></html> HTML handoff("http://www.google.de/",$html);

In reply to Hand off HTML to Internet Explorer by Corion

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.