WWW::Mechanize, save images from a page
am 20.12.2005 13:28:44 von dhanashri_bhate
------=_NextPart_000_004B_01C6058F.04DD44F0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi All,
I am currently automating some UI tests with the help of WWW::Mechanize
module.
I need to save images on a webpage.
I tried using the find_image function to get the reference of the image ( as
shown in the script below ).
But do not understand how I can save that image in a file.
Kindly help!
-------------------------------------
My program:
-------------------------------------
#!/usr/local/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->quiet(0); #turn on warnings
my $host = "abc.xyz.com";
my $url = "http://$host/email";
$mech->get($url);
my $imageref = $mech->find_image( url_regex => qr/gen_login_logo/ );
if ( $mech->success )
{
print "Found the image, reference is : $imageref\n";
}
else
{
print "Did not find the image\n";
}
------------------------------------
The Output:
------------------------------------
-bash-2.05b$ ./save_images.pl
Found the image, reference is : WWW::Mechanize::Image=HASH(0x850d024)
Thanks,
Dhanashri
------=_NextPart_000_004B_01C6058F.04DD44F0--
RE: WWW::Mechanize, save images from a page
am 20.12.2005 13:29:59 von dhanashri_bhate
------=_NextPart_000_004F_01C6058F.31C84AF0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hello All,
I tried to get the complete the URL by concatenating the $imageref->base and
$imageref->url.
And then issue get on this complete url. ( added the code below )
----------------
my $imageurl = $imageref->url ;
my $imagebase = $imageref->base ;
$url = "$imagebase/$imageurl";
print "Getting url $url\n";
$mech->get($url);
----------------
And heres the output:
-bash-2.05b$ ./save_images.pl
Found the image, reference is : WWW::Mechanize::Image=HASH(0x850cb48)
Getting url http://abc.xyz.com/em/images/eui/gen_login_logo.gif
Unable to find document
------------------------
I do see the image manually using IE and can save it. What I want to do is,
emulate this behavior, Open the page in IE, right click on the image and
select "save picture as" and save it.
Thanks,
Dhanashri
_____
From: Dhanashri Bhate [mailto:dhanashri_bhate@persistent.co.in]
Sent: Tuesday, December 20, 2005 5:59 PM
To: 'libwww@perl.org'
Subject: WWW::Mechanize, save images from a page
Hi All,
I am currently automating some UI tests with the help of WWW::Mechanize
module.
I need to save images on a webpage.
I tried using the find_image function to get the reference of the image ( as
shown in the script below ).
But do not understand how I can save that image in a file.
Kindly help!
-------------------------------------
My program:
-------------------------------------
#!/usr/local/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->quiet(0); #turn on warnings
my $host = "abc.xyz.com";
my $url = "http://$host/email";
$mech->get($url);
my $imageref = $mech->find_image( url_regex => qr/gen_login_logo/ );
if ( $mech->success )
{
print "Found the image, reference is : $imageref\n";
}
else
{
print "Did not find the image\n";
}
------------------------------------
The Output:
------------------------------------
-bash-2.05b$ ./save_images.pl
Found the image, reference is : WWW::Mechanize::Image=HASH(0x850d024)
Thanks,
Dhanashri
------=_NextPart_000_004F_01C6058F.31C84AF0--