On an NT I have a script that checks a web page to find if all the links are working. It works fine when checking regular links such as 'www.dom.com' but I need some editing to correct my other problems. Problem I have is I want this to output to a file but I cant get the output part to work. Also it has a problem with: target info such as "http://work.dom.com"  TARGET="_top" it says bad link. Is there anything I can do like a regular expression so it just checks the link and not the TARGET part?
use LWP::UserAgent; use HTTP::Request; use HTTP::Response; my $browser = LWP::UserAgent->new(); $browser->timeout(5); open(HTMLPAGE,"</perl/bin/web.html") or die "$!\n"; while (<HTMLPAGE>) { $buf .= $_; } close HTMLPAGE; while ($buf =~ /<a href="(.*?)">/gis) { my $link = $1; print "Checking $link.\n"; my $request = HTTP::Request->new(GET => $link); my $response = $browser->request($request); if ($response->is_error()) { open(STDOUT, "> /perl/bin/outr.txt"); printf "%s\n", $response->status_line; close( STDOUT ); } $contents = $response->content(); #PLEASE HELP ME ALSO ON THIS PART TO MAKE IT MORE EFFICIENT + if ($contents =~ /Not Found|error|sorry| redirect|autoforward|frameset/ix) { print "Bad Link, $&\n$link.\n\n"; }

In reply to Link script adjustment needed by Anonymous Monk

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.