Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
package Win32::OLE::IE; use strict; use warnings; use Win32::OLE qw(EVENTS); use Time::HiRes qw(sleep); sub new { my ($class, %args) = @_; my $self = {}; bless $self, $class; $self->{IE} = Win32::OLE->new("InternetExplorer.Application") or d +ie $!; my %defaults = ( left => 0, top => 0, height => 400, width => 700, menubar => 1, toolbar => 1, statusbar => 1, visible => 1, %args ); $self->{IE}->{$_} = $defaults{$_} foreach keys %defaults; $self->pause; return $self; } sub content { my ($self) = @_; my $doc = $self->{IE}->{Document}; return $doc->{DocumentElement}->{InnerHTML} if defined($doc->{DocumentElement}); } sub navigate { my ($self, $url) = @_; $self->{IE}->navigate($url); $self->pause(); } sub messageloop { my ($self) = @_; Win32::OLE->MessageLoop(); } sub pause { my ($self) = @_; while ($self->{IE}->{Busy} == 1) { sleep(0.2); } } sub DESTROY { my ($self) = @_; $self->{IE}->Quit(); } sub setform { my ($self, $name, $value, $index) = @_; $index = 0 if !$index; my $cnt = 0; my $doc = $self->{IE}->{Document}; my $forms = $doc->forms; for (my $i = 0 ; $i < $forms->length ; $i++) { my $form = $forms->item($i); for (my $j = 0 ; $j < $form->elements->all->length ; $j++) { my $elemname = $form->elements->all($j)->getAttribute("nam +e"); if ($elemname and $elemname eq $name) { if ($index == $cnt) { $form->elements->all($j)->{value} = $value; return; } else { $cnt++; } } } } die "could not find name=$name index=$index"; } sub pushbutton { my ($self, $name, $index) = @_; $index = 0 if !$index; my $cnt = 0; my $doc = $self->{IE}->{Document}; my $forms = $doc->forms; for (my $i = 0 ; $i < $forms->length ; $i++) { my $form = $forms->item($i); for (my $j = 0 ; $j < $form->elements->all->length ; $j++) { my $elemname = $form->elements->all($j)->getAttribute("nam +e"); my $elemtype = $form->elements->all($j)->getAttribute("typ +e"); if ( $elemname and $elemtype and $elemname eq $name and $elemtype eq 'submit') { if ($index == $cnt) { $form->elements->all($j)->click; $self->pause; return; } else { $cnt++; } } } } die "could not find name=$name index=$index"; } sub clicklink { my ($self, $name, $index) = @_; $index = 0 if !$index; my $cnt = 0; my $doc = $self->{IE}->{Document}; for (my $i = 0 ; $i < $doc->all->length ; $i++) { if ($doc->all($i)->tagName =~ /^A$/) { my $text = $doc->all($i)->innerText; if ($text and $text =~ /\s*\Q$name\E\s*$/) { if ($index == $cnt) { $doc->all($i)->click(); $doc->all($i)->fireEvent("onclick"); $self->pause; return; } else { $cnt++; } } } } die "could not find name=$name index=$index"; } 1; __DATA__ =head1 NAME OLE::IE - Perl extension for automating Internet Explorer =head1 SYNOPSIS use OLE::IE; my $ie = Win32::OLE::IE->new; $ie->navigate("http://www.google.com"); my $html = $ie->content; $ie->setform('q','university of massachusetts', 0); $ie->pushbutton('btnG', 0); $ie->clicklink('Advanced Search',0); =head1 DESCRIPTION An OLE wrapper for Internet Explorer, loosely based on Win32::SAM. =head1 SEE ALSO Win32::SAM

In reply to OLE wrapper for IE by rkg

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (9)
    As of 2020-05-25 06:52 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      If programming languages were movie genres, Perl would be:















      Results (143 votes). Check out past polls.

      Notices?