using LWP::UserAgent Get method

P

Paul

hi, there,

I am learning to use Perl to grab some useful information from
internet. For example to get specified web page.

I tested several web sites and the code works well. But when I tried
on www.officedepot.com, the code does not work any more. the returned
error message is always "Error1: when get http://www.officedepot.com:
500 Can't connect to www.officedepot.com:80 (connect: Unknown error)"

I have no idea what is going wrong. please help me on this


regards

paul


////

use LWP 5.64;
use LWP::UserAgent;
use HTTP::Headers;
use HTTP::Cookies;

$browser = LWP::UserAgent->new;
$browser->timeout(5);
$url ='http://www.officedepot.com';
@ns_headers = (
'Accept'=>'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel, application/
vnd.ms-powerpoint, application/msword, */*',
'Accept-Language'=>'en-us',
'Accept-Encoding'=>'gzip, deflate',
'User-Agent'=>'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 2.0.50727)',
'Proxy-Connection'=>'Keep-Alive',
);

$browser->cookie_jar( HTTP::Cookies->new(
'file' => 'odcookies.lwp',
# where to read/write cookies
'autosave' => 1,
# save it to disk when done
));

$response = $browser->get($url, @ns_headers);
if ($response->is_success)
{
print "Connected with server\n";
}
else
{
print "Error1: when get $url:\t" . $response->status_line . "\n";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top