I guess this is more a question of how to get around a website blocking LWP::UserAgent. I have been using this code for a while now
#!/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.

error in getting index 403 Forbidden try again...
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 Uday

In reply to Sudden problems with LWP::UserAgent by udaybhaskar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.