RE: WWW::Mechanize, save images from a page

"Dhanashri Bhate" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Organization Persistent Systems
Message-ID <[email protected]>
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:[email protected]] 
Sent: Tuesday, December 20, 2005 5:59 PM
To: '[email protected]'
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.