in reply to Re: HTML source grab
in thread HTML source grab

I'll try to point out a few things that immediately leap out at me...

  1. You got the right idea by using -w. I recommend using strict as well to prevent typos, etc. There's plenty of stuff around PerlMonks extolling the virtues of it, so I won't go over it here.
  2. You're not checking the status of opening your file for reading. Try something like this instead: open( F, '<', 'pageinfo.htm' ) or die "Can't open pageinfo.htm: $!";
  3. Your first while loop to print the contents of the file can be shortened to print while <F>;
  4. You're not closing the file after you're done with it.
  5. You should check the result of your LWP request using $request->is_success and show appropriate error messages, etc.
  6. I'm not even sure what you're trying to do with those last two while loops. The $result->content is one big scalar, so one greedy substitution on it will take care of each of these. I.E.: s/</&lt;/g; s/\n/<BR>/g;

And finally, here's a quick example of using HTML::TokeParser to get the meta tags out of an HTML document:

#!/usr/bin/perl -w use strict; use HTML::TokeParser; use LWP::Simple; my $source = get( shift || 'http://www.perlmonks.org' ); my $parser = HTML::TokeParser->new( \$source ); while ( my $tag = $parser->get_tag( 'meta' ) ) { print $tag->[3], "\n"; } print "Done.\n";

I'll leave it as an excercise to use this in a CGI document and format your output accordingly. I hope all this helps... good luck!

"As information travels faster in the modern age, as our days are crawling by so slowly." -- DCFC