HTML::HeadParser to print the title

Discussion in 'Perl Misc' started by Dan Jacobson, Jul 6, 2003.

  1. Dan Jacobson

    Dan Jacobson Guest

    /usr/share/doc/libhtml-parser-perl/examples/htitle will print out the
    title of an HTML document. How do I use the lighter weight
    HTML::HeadParser to do the same? I want to rewrite examples/htitle but
    just don't get it.

    P.S. wouldn't the example be better if it used the more efficient
    tool for that job, HTML::HeadParser?
    Dan Jacobson, Jul 6, 2003
    #1
    1. Advertising

  2. Dan Jacobson <> wrote:

    > /usr/share/doc/libhtml-parser-perl/examples/htitle



    We do not have access to your filesystem, so we don't know what
    "example" it is that you are talking about.

    But that's OK. We don't need to see the example to answer your question.


    > will print out the
    > title of an HTML document. How do I use the lighter weight
    > HTML::HeadParser to do the same?



    By copying the first 4 lines of code displayed when you typed:

    perldoc HTML::HeadParser

    and modifying them for your situation.

    So what do you need us for?


    --------------------------------
    #!/usr/bin/perl
    use strict;
    use warnings;

    my $text = '
    <html>

    <head>
    <title>Perl.org</title>
    <base href="http://www.perl.org/index.shtml">
    <link rel="shortcut icon" href="favicon.ico">
    </head>

    <body bgcolor="#FFFFFF">
    <p>this is the body of the document</p>
    </body>

    </html>
    ';


    # code from the module's documentation

    require HTML::HeadParser;
    my $p = HTML::HeadParser->new;
    $p->parse($text) and print "not finished";

    print $p->header('Title'), "\n"; # to access <title>....</title>
    --------------------------------


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 6, 2003
    #2
    1. Advertising

  3. Dan Jacobson

    Gisle Aas Guest

    Dan Jacobson <> writes:

    > P.S. wouldn't the example be better if it used the more efficient
    > tool for that job, HTML::HeadParser?


    The 'htitle' example script is actually more efficient than
    HTML::HeadParser if there is a <title> tag in the document. It has
    much less fat than HTML::HeadParser, but HTML::HeadParser is able to
    abort the parsing much earlier on title-less documents.

    --
    Gisle Aas
    Gisle Aas, Jul 7, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Klemt
    Replies:
    1
    Views:
    449
    Steve C. Orr, MCSD
    Aug 10, 2003
  2. Replies:
    0
    Views:
    518
  3. Replies:
    1
    Views:
    535
    David
    Apr 24, 2007
  4. soonic
    Replies:
    11
    Views:
    1,772
    soonic
    Jul 27, 2011
  5. Dan Jacobson
    Replies:
    0
    Views:
    84
    Dan Jacobson
    Jul 22, 2003
Loading...

Share This Page