Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^5: LWP::Simple get function...

by maverick (Curate)
on Dec 17, 2007 at 16:15 UTC ( #657447=note: print w/replies, xml ) Need Help??

in reply to Re^4: LWP::Simple get function...
in thread LWP::Simple get function...

Wow, a reply to a seven year old post. Is that a record?

Your 400 error message is probably because you're using a short url:

as opposed to a full url
As for saving the output in a given directory; you'll need to make a couple of changes. First you'll need to make the program take two parameters, the URL you want to get and the save location. For the sake of simplicity, let's not only specifiy the directory to save in, but also the filename to save the page into.
use LWP::UserAgent; use HTTP::Request::Common; if ($#ARGV != 1) { print STDERR "Usage: $0 \"URL to fetch\" \"save location\"\n"; exit; } my $agent = new LWP::UserAgent; $agent->proxy(['http','ftp'],''); my $req = GET($ARGV[0]); my $res = $agent->request($req); if ($res->is_success) { open(OUTPUT,">".$ARGV[1]) || die "Can't open outfile: $!"; print OUTPUT $res->content; close(OUTPUT); } else { print $res->status_line,"\n"; }
Note the differences between the two. The first "if" has changed, as well as the usage message. Then there are the added "open" and "close" statements, and the alteration to the "print" statement.

Then you can use it like this: /tmp/ +ml
The output directory will have to exist first and the program doesn't do any sanity or security checks on the filename you give it. There are lots of references here on how to do add that sort of bulletproofing.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://657447]
[karlgoethebier]: marioroy ;Men need a challenge
Lady_Aleena remembers winning dodgeball and wonders why parents who played it will not let their kids play it.
[marioroy]: Disciplus My wife and I went on vacation. At work, I was stuck polling SNMP from 20 million devices. It would hang at 80,000. On the mist boat, hear a voice to enable grace in the design that 10x and more performance awaits.
[Lady_Aleena]: Women need challenges too karlgoethebier. 8)
[marioroy]: s/hear/heard/
[karlgoethebier]: Discipulus: No. See https://en. wiki/Tribe_( Native_American)
[karlgoethebier]: They took Unix from some aliens
[marioroy]: Perl is so powerful that it can poll 40 metrics from 20 million devices in 40 minutes using 4 nodes only.
[karlgoethebier]: http://www. aliens.htm
[Lady_Aleena]: marioroy, I can't decide whether or not to move my RolePlaying:: Random:: modules to just Random::. I'm not as sophisticated as most here.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2017-05-29 08:53 GMT
Find Nodes?
    Voting Booth?