#!/usr/bin/perl -w use diagnostics; use strict; use LWP; use Date::Manip; use HTTP::Cookies; use URI; my $cookie_jar; $cookie_jar = HTTP::Cookies->new( 'file' => 'cookies.lwp', 'autosave' => 1, ); my $url = URI->new ('http://www.nseindia.com/marketinfo/indices/indexwatch.jsp'); my $browser = LWP::UserAgent->new(timeout=>'45', agent=>'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) G +ecko/20101012 Firefox/3.6.11'); $browser->cookie_jar($cookie_jar); push @{ $browser->requests_redirectable }, 'POST'; my $html_page; my $response = $browser->get($url); if ($response->is_error()) { print "error in getting index ".$response->status_line()."\n"; print "try again...\n"; } else { $html_page = $response->content(); if ($html_page =~ m{<a href=#top>Top</a></center>}) { print "got Index\n"; } elsif ($html_page =~ m/Your request could not be processed/) { print "\t\t\tNSE is down. Trying again...\n\n"; } else { print "$html_page\n"; print "failed to get index. Trying again...\n"; } }
This code worked till yesterday. However today I am hitting the 403 error.
I used the same UserAgent as that of Mozilla which successfully retrieves the page. I tried it from different IP address to ensure that my IP is not blocked(I run it once a day and am not running a bot) Looking for some help in getting this going again. Thanks Udayerror in getting index 403 Forbidden try again...
In reply to Sudden problems with LWP::UserAgent by udaybhaskar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |