Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: save image on web

by saskaqueer (Friar)
on Dec 21, 2004 at 05:51 UTC ( #416388=note: print w/ replies, xml ) Need Help??


in reply to Re^2: save image on web
in thread save image on web

In addition to NetWallah's suggestions, the site may also be blocking according to the referrer URL, or by the user-agent of the "browser", or possibly even by a cookie (if the image URL is that of a CGI script). Try this code (which is completely untested):

#!perl -w use strict; use LWP::UserAgent; use HTTP::Request::Common; my $url = 'http://www.server.com/path/to/image.gif'; my ($referer) = $url =~ m!^(https?://[^/]+/)!; my $ua = LWP::UserAgent->new( agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)', cookie_jar => {} ); # probably not needed, only needed if cookie is used # to test for "real browser". highly unlikely, but you # never know! $ua->get($referer); my $req = HTTP::Request->new( GET => $url ); $req->referer($referer); print $ua->request($req)->content();


Comment on Re^3: save image on web
Download Code
Re^4: save image on web
by kcella (Beadle) on Dec 21, 2004 at 12:32 UTC
    Got the following message when trying to run saskaqueer's code:

    LWP will support https URLs if the Crypt::SSLeay module is installed. More information at <http://www.linpro.no/lwp/libwww-perl/README.SSL>.

    I tried installing Crypt::SSLeay, but ppm3 does not have a win32 version.

    As for NetWallah's suggestions, I have a direct URL to the image, so it is not in a frame. It is also under 4 MB, not generated by javascript and not beign re-directed. I can download it manually just fine. I would post the URL, but it would not help since it is part of a password protected site and it would just redirect you to a login.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://416388]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-21 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (103 votes), past polls