tags:

views:

58

answers:

2
use LWP::Simple;
use HTML::LinkExtor;
use Data::Dumper;
#my $url = shift @ARGV;
my $content = get('example.com?GET=whateverIwant');
my $parser = HTML::LinkExtor->new(); #create LinkExtor object with no callbacks
$parser->parse($content); #parse content

now if I want to send POST and COOKIE info as well with the HTTP header how can I configure that with the get funciton? or do I have to customize my own method?

My main interest is Cookies! then Post!

+4  A: 

LWP::Simple is for very simple HTTP GET requests. If you need to do anything more complex (like cookies), you have to upgrade to a full LWP::UserAgent. The cookie_jar is a HTTP::Cookies object, and you can use its set_cookie method to add a cookie.

use LWP::UserAgent;

my $ua = LWP::UserAgent->new(cookie_jar => {}); # create an empty cookie jar

$ua->cookie_jar->set_cookie(...);

my $rsp = $ua->get('example.com?GET=whateverIwant');
die $rsp->status_line unless $rsp->is_success;
my $content = $rsp->decoded_content;
...

The LWP::UserAgent also has a post method.

cjm
+2  A: 

You might want to use WWW::Mechanize instead. It already glues together most of the stuff that you want:

 use WWW::Mechanize;

 my $mech = WWW::Mechanize->new(
    cookie_jar => { ... }
    );

 $mech->cookie_jar->set_cookie(...);

 $mech->get( ... );

 my @links = $mech->links;
brian d foy
You don't need `cookie_jar => {}` here, because WWW::Mechanize already defaults to that (unlike its base class, LWP::UserAgent, which does not create a cookie_jar unless requested to).
cjm
Heh, I can never remember which way it goes. :)
brian d foy