using LWP::UserAgent Get method

Discussion in 'Perl Misc' started by Paul, Jun 5, 2007.

  1. Paul

    Paul Guest

    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";
    }
    Paul, Jun 5, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gaurav

    Problem using LWP::UserAgent

    Gaurav, Oct 2, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    236
    Tad McClellan
    Oct 2, 2003
  2. Rubel Kanubel

    Post radiobuttons (forms) using lwp-useragent

    Rubel Kanubel, Oct 12, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    227
    Anno Siegel
    Oct 13, 2003
  3. Leif Wessman
    Replies:
    0
    Views:
    140
    Leif Wessman
    Sep 9, 2004
  4. garhone

    LWP UserAgent: unable to 'get'

    garhone, Dec 29, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    95
    Samwyse
    Dec 30, 2005
  5. arz
    Replies:
    0
    Views:
    77
Loading...

Share This Page