J
jjliu
Could someone point me out that why the following perl program only print
'title'. I expect the contents in h1, keywords and description to print out
as well. thanks.
JJL
#!/usr/bin/Perl
use LWP::Simple;
use HTML::TokeParser;
my $content = get( "http://www.perl.com" ) or die $!;
my $stream = HTML::TokeParser->new( \$content ) or die $!;
while ( $tag = $stream->get_tag("title") )
{
my $title=$stream->get_trimmed_text;
print "Title: $title\n";
}
while ( $tag = $stream->get_tag("h1") )
{
my $head1=$stream->get_trimmed_text;
print "Heading1: $head1\n";
}
while ( $tag = $stream->get_tag("meta") )
{
if ($tag->[1]{name}=~/keywords/i)
{
print $tag->[1]{content};
}
if ($tag->[1]{name}=~/description/i)
{
print $tag->[1]{content};
}
}
'title'. I expect the contents in h1, keywords and description to print out
as well. thanks.
JJL
#!/usr/bin/Perl
use LWP::Simple;
use HTML::TokeParser;
my $content = get( "http://www.perl.com" ) or die $!;
my $stream = HTML::TokeParser->new( \$content ) or die $!;
while ( $tag = $stream->get_tag("title") )
{
my $title=$stream->get_trimmed_text;
print "Title: $title\n";
}
while ( $tag = $stream->get_tag("h1") )
{
my $head1=$stream->get_trimmed_text;
print "Heading1: $head1\n";
}
while ( $tag = $stream->get_tag("meta") )
{
if ($tag->[1]{name}=~/keywords/i)
{
print $tag->[1]{content};
}
if ($tag->[1]{name}=~/description/i)
{
print $tag->[1]{content};
}
}