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();

Replies are listed 'Best First'.
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.