How do I get and save an image off of a web page

I want to grab a web page via HTTP:Request and then parse it and grab an =
image off of it and save that image to the hard disk. Has anyone done =
this and/or can anyone point me in the right direction?

Thanks,

Guy Davis

0
guy
3/27/2002 4:29:06 PM
perl.beginners 29388 articles. 4 followers. Follow

3 Replies
454 Views

Similar Articles

[PageSpeed] 3

This would do it...

#!/usr/bin/perl

use LWP::Simple;
use strict;

my $content=get("http://www.images.com/image.jpg");
open(OUT, ">image.jpg") or die $!;
binmode(OUT);
print OUT $content;
close(OUT);

Regards,
Agustin Rivera
Webmaster, Pollstar.com
http://www.pollstar.com



----- Original Message -----
From: "Guy Davis" <guy@yournaturewithin.com>
To: <beginners@perl.org>
Sent: Wednesday, March 27, 2002 8:29 AM
Subject: How do I get and save an image off of a web page


> I want to grab a web page via HTTP:Request and then parse it and grab an
image off of it and save that image to the hard disk. Has anyone done this
and/or can anyone point me in the right direction?
>
> Thanks,
>
> Guy Davis
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org

0
lists
3/27/2002 4:46:45 PM
Sorry, should clarify that would just download an image for you (it's
probably pretty obvious)...  If I were to parse an image location off a
webpage, I'd first spool up the whole page in a variable, break the variable
down by the bracket '<' into an array, then parse each item of the array
with this ...

$data=~ /src="*(.*?)( |>|")/;

The images then could be found in $1.

Agustin Rivera
Webmaster, Pollstar.com
http://www.pollstar.com



----- Original Message -----
From: "Guy Davis" <guy@yournaturewithin.com>
To: <beginners@perl.org>
Sent: Wednesday, March 27, 2002 8:29 AM
Subject: How do I get and save an image off of a web page


> I want to grab a web page via HTTP:Request and then parse it and grab an
image off of it and save that image to the hard disk. Has anyone done this
and/or can anyone point me in the right direction?
>
> Thanks,
>
> Guy Davis
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org

0
lists
3/27/2002 4:57:36 PM
I just had to do this for a project and found that that HTML::LinkExtor
module works perfect for this!  There is even an example in the docs that
shows how to filter out everything except images if i remember correctly.

Just do a search for Extor at search.cpan.org

Good luck!
Brent



                                                                                                                                       
                      "Guy Davis"                                                                                                      
                      <guy@yournaturew         To:      <beginners@perl.org>                                                           
                      ithin.com>               cc:                                                                                     
                                               Subject: How do I get and save an image off of a web page                               
                      03/27/02 10:29                                                                                                   
                      AM                                                                                                               
                                                                                                                                       
                                                                                                                                       




I want to grab a web page via HTTP:Request and then parse it and grab an
image off of it and save that image to the hard disk. Has anyone done this
and/or can anyone point me in the right direction?

Thanks,

Guy Davis


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org





0
Brent_Michalski
3/27/2002 7:37:48 PM
Reply: