Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
We don't bite newbies here... much
 
PerlMonks  

Re: Re: HTML source grab

by patgas (Friar)
on Mar 12, 2002 at 16:45 UTC ( [id://151239]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151239]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.