Whole link tag handling with HTML::Parser

T

* Tong *

Hi,

I've been looking at HTML::parser and HTML::LinkExtor trying to
figure out how to handle the html tags as a whole. But I'm still
confused and feel at lost about their even handling mechanism.

All that I'm trying to do is to call the following even handler
after a whole html link tag has bee parsed.

tag_handler(){
my ($tag, $tag_open, $tag_content, $tag_close) = @_;
...
}

So, '<A HREF="link.html">link</a> ' will give me:

($tag, $tag_open, $tag_content, $tag_close) =
('a', 'A HREF="link.html"', 'link', '/a');

and an '<IMG SRC="img.jpg" lowsrc="img.gif" alt="Image">' will give
me:

($tag, $tag_open, $tag_content, $tag_close) =
('img', 'IMG SRC="img.jpg" lowsrc="img.gif" alt="Image"', undef, undef);

Seems to me the right way is to start with is a general purpose
start handler, in which different end handlers are assigned
according to the start tag. This is where I get lost and don't
know how to do. I'm wondering if anyone could be kind enough to
provide me a first draft, showing me how this can be done. It will
be much appreciated.

NB, this is only to explain the concept. Maybe passing back the
html tag as HTML::Element/HTML::Entities so that the tag attributes
have already been processed is a better idea.

Thanks a lot.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top