Well,
All I have to say is that my basic understanding of perl language and how to
download a link may be very little, and probably I do need a tutor as you
said!

But I'm not here to spoil any domain reputation. My query was a genuine one!
And I'm really surprised to get this reply :(  

Anyway, about downloading a link, all I had done earlier is use
WWW::Mechanize, get($url) and then use function save_content to save it in a
file, which works very well.
I had used it earlier to get a ZIP file, the file was downloaded but could
not be opened. That was the time when someone on this same list (sorry! I
don't remember the name) had suggested using binary copy instead of using
the save_content function. 
That worked, and since this image I want to save is also not a text file, I
followed the same approach. 

But, in the code I posted I had missed a very important line $mech->get (
$url ) , before the starting the binary copy. After adding this line the
script works perfectly fine.

Dhanashri

======== the code ========

#!/usr/local/bin//perl -w
use strict;
use WWW::Mechanize;

my $mech = WWW::Mechanize->new();
$mech->quiet(0);                #turn on warnings

my $host = "search.cpan.org";
my $url = "http://$host/~petdance/WWW-Mechanize-1.16/";;
$mech->get($url);
my $imageref = $mech->find_image( url_regex => qr/cpan-10/ );
my $img_link;
if ( $mech->success ) {
        $img_link=$imageref->url();
        print "url to image is: http://$host$img_link\n";;

        $url = "http://$host$img_link";;
        $mech->get ( $url );      ## had missed this!

        if ( $mech->success ) {
                print "Get url - Succesful\n";
                my $filename = './pic.jpg';

                # binary copy of contents to a file

                open my $fh, ">", $filename or die $!;
                binmode $fh;
                print $fh $mech->content;
                close $fh;
        }
        else
        {
                print "Get url - failed\n";
        }
}
else
{
    print "Did not find the image\n";
}
===========================


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 22, 2005 12:22 AM
To: [EMAIL PROTECTED]
Subject: RE: WWW::Mechanize, save images from a page

>>>Obviously I don't know what you're doing.  But it appears that you don't
know
>>>what you're doing, like as in one who is totally poking around in the
dark. 
>>>Otherwise you would at least inquire somewhere about how to download
$url.  or,
>>>maybe it's this is someone playing a game.  Or, are you out to set a bad
name/reputation on this list for domain name that includes .in as a part of
the domain?

>>> This is not part of the normal posting ettiquet on this list or any list
that I
>>> know of for that matter.  Had I known then what I know now, I wouldn't
have replied to your query.

>>> I don't participate in this sort of posting nor do I enable it.  I'm
outta here on this one unless some serious change happens and happens quick.

>>> You need too much help in order for you to be helped here.  Contract
yourself a tutor or learn more as I mentioned earlier and then come back
here once that has happened.

>>>It appears that this is liable to end up as one of them: "ploink"  ??.
We'll see.

>>>-- 
>>>Alan.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to