http://www.perlmonks.org?node_id=1143641


in reply to Use LWP get no URL response

Hi, I think you miss accept type in the code. here I attached correct code for your help.
use strict; use HTTP::Cookies; use LWP::UserAgent; my $ua = LWP::UserAgent->new(show_progress=>1); $ua->agent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/2010010 +1 Firefox/26.0"); $ua->timeout(30); $ua->cookie_jar({}); my $filename ="indiegogo"; my $cookie_file = $filename."_cookie.txt"; unlink($cookie_file); my $cookie = HTTP::Cookies->new(file=>$cookie_file,autosave=>1); $ua->cookie_jar($cookie); my $url = 'http://www.digikey.com/product-search/en?KeyWords=C0603C474 +K4PACTU&WT.z_header=search_go'; my $req = HTTP::Request->new(GET=>$url); $req->header("Accept"=>"text/html,application/xhtml+xml,application/xm +l;q=0.9,*/*;q=0.8"); $req->header("Content-Type"=>"application/x-www-form-urlencoded"); my $res = $ua->request($req); $cookie->extract_cookies($res); $cookie->save; $cookie->add_cookie_header($req); my $code = $res->code(); print $code,"\n"; if($code =~ m/50/is) { sleep 1000; goto REPEAT; } my $content = $res->content(); open sr,">digikey.html"; print sr $content; close sr;
Thanks, Sathish