For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > July 2004 > How to use Mozilla within Perl (to replace IE)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to use Mozilla within Perl (to replace IE)
DG

2004-07-29, 3:57 pm

Hello and thanks for the help,

I've used IE within Perl to access web sites. Given the recent IE security
problems, I'd like to replace it with Mozilla 1.71.
Unfortunately, I don't know how.

Below is an example of how I have used IE within Perl. How would I change
this code to access Mozilla?

thanks for the help,
DG


use Win32::OLE;

$BROWSER = Win32::OLE->new('InternetExplorer.Application'); #open the
browser
$BROWSER->with(Visible => 1, Top => 1, Left => 1, Height => 50, Width =>
500); #shrink the browser window, and place it in the upper left corner
$BROWSER->Navigate("http://wwws.yahoo.com"); #get the
cookies

do #wait until the first page finishes loading (to get the cookies) before
logging in
{
select(undef,undef,undef,0.1); #sleep 0.1 seconds (finer time resolution
than "sleep" command)
$stat=$BROWSER->{Busy}; #get the status of the browser load
}
while ($stat); #continue looping if the browser is NOT yet
done loading

# get the HTML data
$body=$BROWSER->Document->{body}; #get the hash string
returned by the browser
$mystring= $body->{innerHTML}; #get the HTML data from
browser
#$mystring= $body->{innerTEXT}; #removes all HTML commands
leaving only the text




David K. Wall

2004-07-29, 3:57 pm

DG <invalid@invalid.invalid> wrote in message
<news:ZzbOc.179684$%_6.81508@attbi_s01>:

> I've used IE within Perl to access web sites. Given the recent IE
> security problems, I'd like to replace it with Mozilla 1.71.


Just use LWP::UserAgent and HTTP::Request. See lwpcook for examples and
lwptut for a tutorial on using the LWP libraries.

LWP (short for ``Library for WWW in Perl'') is a very popular
group of Perl modules for accessing data on the Web.

DG

2004-07-29, 8:56 pm


"David K. Wall" <dwall@fastmail.fm> wrote in message
news:Xns95359A268C7ACdkwwashere@216.168.3.30...
> DG <invalid@invalid.invalid> wrote in message
> <news:ZzbOc.179684$%_6.81508@attbi_s01>:
>
>
> Just use LWP::UserAgent and HTTP::Request. See lwpcook for examples and
> lwptut for a tutorial on using the LWP libraries.
>
> LWP (short for ``Library for WWW in Perl'') is a very popular
> group of Perl modules for accessing data on the Web.
>


Thanks for the reply.

I've used these libraries in the past (prior to switching to IE), and found
they didn't meet my needs. For example: sometimes I need a browser window
to open for the user to view, and these libraries don't do that. Also, I've
had problems with secure sites (https://) not liking the way these libraries
handle cookies (usually because these sites use JavaScript to modify
cookies). I worked around these problems for a while, but finally decided
that it was just easier to just use a full blown browser. That's when I
switched to using IE within Perl (I also found a side benefit that I didn't
need to upgrade the code when new developments in web pages occurred,
because handlers for these upgrades were built into the browser updates).
So, based on this past experience, I'd like to use a full browser within
Perl. That's why I'm asking how to use Mozilla within Perl.

But thanks for taking the time to suggest a solution,
DG


Shailesh Humbad

2004-07-29, 8:56 pm

DG wrote:

> "David K. Wall" <dwall@fastmail.fm> wrote in message
> news:Xns95359A268C7ACdkwwashere@216.168.3.30...
>
>
>
> Thanks for the reply.
>
> I've used these libraries in the past (prior to switching to IE), and found
> they didn't meet my needs. For example: sometimes I need a browser window
> to open for the user to view, and these libraries don't do that. Also, I've
> had problems with secure sites (https://) not liking the way these libraries
> handle cookies (usually because these sites use JavaScript to modify
> cookies). I worked around these problems for a while, but finally decided
> that it was just easier to just use a full blown browser. That's when I
> switched to using IE within Perl (I also found a side benefit that I didn't
> need to upgrade the code when new developments in web pages occurred,
> because handlers for these upgrades were built into the browser updates).
> So, based on this past experience, I'd like to use a full browser within
> Perl. That's why I'm asking how to use Mozilla within Perl.
>
> But thanks for taking the time to suggest a solution,
> DG
>
>


Mozilla can't be automated as an OLE/ActiveX object the way Internet
Explorer can. I did find this:

http://www.iol.ie/~locka/mozilla/control.htm

Mozilla ActiveX control, but I know nothing about it. It might work
for you.

In general, to retrieve/post HTTP, use the LWP libraries. You can
always launch Mozilla easily by writing a temporary HTML file that
does anything special you need it to, and then using a
system("c:\program files\...\mozilla.exe") to open it. Look here for
Mozilla command line options:

http://www.mozilla.org/docs/command-line-args.html
Joe Smith

2004-07-30, 8:56 am

Shailesh Humbad wrote:

> In general, to retrieve/post HTTP, use the LWP libraries.


Yes, but if you know ahead of time that the HTML will be containing
JavaScript, then you'll want to use a browser instead of just LWP.
-Joe
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com