Friday, November 27, 2009

Automating Internet explorer applicatios with Win32::OLE to open any website

Introdution
Perl has a very good module, for automation in Win32 system, called as Win32::OLE. Everyone uses internet now. There are many place where you may need to fill the forms, which is very tedious job, and it requires a lot of effort and time if form has many data entry points. So you will definitely think of getting this work automated somehow, so that you don't have to fill the complete form. Also there are a lot of e-books available on net for online reading, but there main problem comes how to read e-book if you don't have internet access at any point. I wanted to get all .html pages of any online book saved to my system without doing it manually.
The best solution is to get that book downloaded for you either in html format or .chm or .pdf. All this can be done using Win32::OLE module which will automate the apllication as per your requirement.

Usage:
The first thing is how to start Iexplorer.exe, without clicking on ICON of IE. You can start IE in that way but you won't be able to do anything you want.
So to open IE :
my $IE = WIn32::OLE->new("InternetExplorer.Application") || die "Couldn't open IE\n" ;
It's good but problem was that I was not able to see IExp.So I again read the document and found that there is a property which should be set:
$IE->{visible} = 1;
This time IE will get opened but with blank screen, so to open any web page use following:
$IE->navigate("www.google.co.in");
FOr more information on how I get to know about navigate(), I installed a program call OLEview.exe.( It's available as part of resource tool kit on microsoft website as freeware)  After downloading and installing this package: got to C:\Program Files\Windows Resource Kits\Tools and Run oleviw.exe and you will find InternetExplorer application wihitn "automation" and in that within methods, click on "navigate" so you will find following information:

[id(0x00000068), helpstring("Navigates to a URL or file.")].
void Navigate(
    [in] BSTR URL,
    [in, optional] VARIANT* Flags,
    [in, optional] VARIANT* TargetFrameName,
    [in, optional] VARIANT* PostData,
    [in, optional] VARIANT* Headers);
So now you will navigate to your first site.
In next posts I will tell you how to navigate to links present in that page.

No comments:

Post a Comment