(OP failed to call my attention to the fact that OP sent this to me off list) (and I already unknowingly replied this directly to OP) (so, here it is now for list) (grins, people :-)
On Thu, 22 Dec 2005 10:52 , Dhanashri Bhate <[EMAIL PROTECTED]> sent: > >I surely missing something very simple! :(( (grins, people :-) Absolutely. The simple thing is that you need to learn more about both the basics of Perl and the mechanics of what downloading means versus instead to nest an if like you did and open a totally irrelevant filehandle, this filehandle that has nothing whatsoever to do with your download, has no connection whatsoever to your download that you needed to download. [ . . ] >I just copied your script, and added a get on the image link. It gives me > >success and I can save the content. ( Pls see attached script ), but what I > >receive in the file is not a picture but the complete page :( No. your irrelevant file handle that you added does not download any web page, not from the internet. What you did is you added a nested if (totally unneccesary to do so) -- Here's the relevant section that you added: my $ref_type; my $img_link; if ( $mech->success ) { $img_link=$imageref->url(); $ref_type=ref $imageref; print "Found the image the type of reference is : $ref_type\n"; print "the image link is: $img_link\n"; print "url to image is: http://$host$img_link\n"; # view that url in a web browser and/or # download here will get/put to hard drive $url = "http://$host$img_link"; #### I addedd the following ############## print "Getting page $url\n"; 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"; } # end end of relevant section ------------------------------ $url = "http://$host$img_link"; # is this stringification. if so, bad, very bad. naughty you. otherwise, silly me. You didn't read my comments in the code about downloading with LWP or wget or some other method to download. You need to download $url. Instead you nest an if and open an totally irrelevantly named filehandle that has nothing whatsoever to do with $url 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. ---- Msg sent via CWNet - http://www.cwnet.com/
#!/usr/local/bin//perl -w use strict; use diagnostics; 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 $ref_type; my $img_link; if ( $mech->success ) { $img_link=$imageref->url(); $ref_type=ref $imageref; print "Found the image the type of reference is : $ref_type\n"; print "the image link is: $img_link\n"; print "url to image is: http://$host$img_link\n"; # view that url in a web browser and/or # download here will get/put to hard drive $url = "http://$host$img_link"; #### I addedd the following ############## print "Getting page $url\n"; 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"; } # end
<<attachment: pic-1.jpg>>
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>