Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 perusing the Monastery: (7)
As of 2015-07-04 21:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls