How can I get the title from HTML file? 
Author Message
 How can I get the title from HTML file?

Hi, everyone!!!!

I am trying to get a title from one HTML file.  This is my subroutine
that I did.
This will read first line of the file and set to title.  It doesn't work
well.
Can some one help?  Do you have better subroutine?
Thanks

sub format_output{

    local ($line, $strings, $title);
    (open(FILENAME, $file_path)) || print "can'topen $file_path in
file_format";

    print "Content-type: text/html\n\n";
    print "<html><body>";
    while( $line = <FILENAME>){
        if(length($line)){
                $line =~ s/\<(.*?)\>//g;
                $line =~ s/\n//g;
                $line =~ s/&nbsp\;|&lt\;|&gt\;//g;

        }
        if  (!$title && $line){
                if ( $line )  {
                $title = $line;
                print $title,"<br>";
                next;
        }
        $strings = $strings.$line;
        if (length($strings) >= 500){
                last;
        }
    }
    $strings  =~ s/\<(.*?)\>//g;
    $strings =~ s/\n//g;
    print "strings",$strings,"\n";
    print "</body></html>";
    close FILENAME;
    return $strings;

Quote:
}



Wed, 20 Sep 2000 03:00:00 GMT  
 How can I get the title from HTML file?

On Sat, 04 Apr 1998 09:07:04 -0500, "Seong Y. Kim"

Quote:

>Hi, everyone!!!!

>I am trying to get a title from one HTML file.  This is my subroutine
>that I did.

The Module HTML::HeadParser is your best bet if you only want the
title (or other <HEAD> block stuff such as META tags and so on).
However to get at the whole file you will be better to use
HTML::Parser although this may enmesh you in the Object thing more
than you might wish at the present time. I have an example of the
modules use in a fairly crude and only partially finished HTML
Beautifier at:
http://www.btinternet.com/~gellyfish/resources/hteauty.pl
I wouldnt take it too seriously as a program though.

/J\

/J\

Jonathan Stowe
See the MetaFaq at http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm



Wed, 20 Sep 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. getting the title out of an HTML-page

2. Generating a title for a HTML Document without a title tag

3. Getting page title

4. $title and ($title) as lvalue

5. - Grabbing Title from HTML

6. Replace between data HTML <title> tags

7. REGEXP question : Trying to extract title from HTML

8. Parsing an html document for the title (don't flame, I have searched around)

9. Finding the TITLE to an HTML page

10. Finding the TITLE to a HTML page

11. Finding the TITLE to a HTML page

12. HTML document title

 

 
Powered by phpBB® Forum Software