Barrucadu Established Member โ 20 โ Impact 64 Aug 25, 2006 584 views 3 replies #1 Perl Question edit: Fixed original error, now I need help with something else ----- How can I get the title of a page with LWP? Last edited: Aug 25, 2006
Perl Question edit: Fixed original error, now I need help with something else ----- How can I get the title of a page with LWP?
sjaguar13 Established Member โ 20 โ Impact 10 Aug 25, 2006 #2 You can use the TokeParser: This assumes the content is returned to $content Code: $parser = HTML::TokeParser->new(\$content); $parser->get_tag("title"); $title = $parser->get_token; print $title->[1], "\n" if $title; Or you could grep $content to find what's between the title tags.
You can use the TokeParser: This assumes the content is returned to $content Code: $parser = HTML::TokeParser->new(\$content); $parser->get_tag("title"); $title = $parser->get_token; print $title->[1], "\n" if $title; Or you could grep $content to find what's between the title tags.
Barrucadu Established Member โ 20 โ Impact 64 Aug 25, 2006 #3 I've tried grep - but there is a problem: Code: @title = grep("<title>[a-z]</title>",$content); push(@filetitles,@title); But that always returns "HTTP::Request=HASH(0x1a8dab0) " edit: fixed, used the wrong method for getting the content Last edited: Aug 25, 2006
I've tried grep - but there is a problem: Code: @title = grep("<title>[a-z]</title>",$content); push(@filetitles,@title); But that always returns "HTTP::Request=HASH(0x1a8dab0) " edit: fixed, used the wrong method for getting the content
M mp123456 Established Member โ 15 โ Impact 3 Aug 29, 2006 #4 well if you're looking for a regex: my ($title) = ($content=~m@<title>\s*(.*?)\s*</title>@is);