Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Controlling IE and making it QUIT !!

by BrianP6 (Initiate)
on Feb 17, 2013 at 12:32 UTC ( #1019128=perlquestion: print w/ replies, xml ) Need Help??
BrianP6 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Hopefully this will be relatively straight forward, but I'm tearing my hair out at the moment. I am trying to automate a simple lookup to a web page for a game that I'm on. I need to increase my hits to one of my status pages. I have found out that a 'hit' seems to be related to the browser session, and that the best thing to do is to hit the web page, close explorer and wait 30 minutes before trying again. So, I've googled, and found out how to control IE via OLE and use the Events triggered to catch where the DocumentComplete and OnQuit events are triggered. As below

use strict; use Win32::OLE qw(EVENTS); my $URL = "http://REQUIRED WEB PAGE"; my $IE; my $timeout; displaywebpage(); sub Event { my ($Obj,$Event,@Args) = @_; my $IEObject; print "Here is the Event: $Event\n"; if ($Event eq "DocumentComplete") { $IEObject = shift @Args; print "URL: " . $IEObject->Document->URL . "\n"; print "Now quit IE\n"; $IE->Quit; } elsif ($Event eq "OnQuit") { Win32::OLE->QuitMessageLoop(); } } sub displaywebpage { $IE = Win32::OLE->new("InternetExplorer.Application") || die "Could not start Internet Explorer.Application\n"; $IE->{visible} = 1; Win32::OLE->WithEvents( $IE, \&Event, 'DWebBrowserEvents2' ); $IE->Navigate($URL); Win32::OLE->MessageLoop(); $timeout = 30*60; # n seconds print "Wait for $timeout seconds\n"; $timeout -= sleep $timeout while $timeout > 0; print "Now start again\n"; displaywebpage(); }

The problem is that the OnQuit event fires before IE quits and even with the OnQuit event handler only terminating the message loop, so that it goes back to the perl script to fire another IE after the timeout, the IE window only really quits at the point that the new window is opened.

I want the IE window to quit, then wait for 30 minutes before opening a new window to do the same thing.

Any wisdom you can supply would be most welcome

Thanks

Comment on Controlling IE and making it QUIT !!
Download Code
Re: Controlling IE and making it QUIT !!
by davies (Vicar) on Feb 17, 2013 at 13:29 UTC

    I've never tried controlling IE from Perl, so treat this suggestion with great suspicion. To avoid the sort of behaviour you describe in Excel, I would use $xl->EnableEvents = 0. It might be worth trying something as simple as changing $xl to $IE.

    Regards,

    John Davies

Re: Controlling IE and making it QUIT !!
by Gangabass (Priest) on Feb 17, 2013 at 13:49 UTC
      what would that accomplish?
        Using this module we can just write:
        $ie->closeIE();
        to close IE instance.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019128]
Approved by davies
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-09-19 22:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (149 votes), past polls