Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download a single picture 1

Status
Not open for further replies.

timgerr

IS-IT--Management
Joined
Jan 22, 2004
Messages
364
Location
US
Here is a question, how can I download in perl a picture
Code:
[URL unfurl="true"]http://www.somthing.com/picture1.jpeg[/URL]
without using any plugens?

is there anyway to capture a picture?

Thanks




-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!
 
You'll need LWP (lib to do anything like that. It comes standard with Perl though so you shouldn't need to install anything.

Code:
use LWP::Simple;
my $image = get "[URL unfurl="true"]http://www.somthing.com/picture1.jpeg";[/URL]

# save it to a local file??
open (FILE, ">./picture1.jpeg");
binmode FILE; # Binary writing
print FILE $image;
close (FILE);
 
wget would do it too ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Thanks for the replies, I was wondering if there was a way to do this without any mods.

--T

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
You could deconstruct lib but personally I'd use the module, and it should be part of any recent perl install as standard ... as Kirsle pointed out

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
You wouldn't happen to be one of those people who believes that using modules is a lazy way and that those who do it can't call themselves real programmers because they don't manually code every bit and detail are you?

Deconstructing LWP would have you deconstruct LWP::UserAgent, which would in turn need you to deconstruct HTTP::Request, HTTP::Response, HTTP::Date, which in turn requires HTTP::Message, which uses HTTP::Headers....

And much further down the line, one of these modules probably uses IO::Socket or Socket (which IO::Socket also uses, so either way it all boils down to Socket). And Socket appears to be an XS module, meaning it isn't pure Perl but has some C components to it.

Long story short, you could spend days and weeks writing your own method of grabbing an image from a website by scratch without having one 'use' statement in your code.... OR, you can just use LWP and have it all done in one quick go, and then you'll have all that free time to explore other things.
 
Kirsle, I like your essay - have star.
 
No…No.. Someone asked me to look into this for a training exercise. I didn’t want to get into the modules yet.

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
A good programmer has a lazy element, and if you're going to be good at perl, learn to love modules, and CPAN, trust me it's time well spent, and you will reap the rewards.

As a training exercise, what are you training for? IMO it's a bit like training for a marathon when you're entered for the 100m dash ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I have a friend that wants me to write some labs for him. He gave me the scenarios and I have to write some code for him. The problem that I have is the first scenario is to grab a picture from a webpage and I didn't want to use a module for the first lab. I know how to do it with LWP but was wondering if there was another way (that I didn’t know) to do it.

Thanks for the help


-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
just shell to wget, it's legitimate ... PHP has support for this, but if you dig into it, it still depends on IO::Socket, or similar

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top