Re: Limiting Toke::Parser
- From: noreply@xxxxxxxxx (Gunnar Hjalmarsson)
- Date: Sat, 28 Jun 2008 18:27:47 +0200
Rob Dixon wrote:
Gunnar Hjalmarsson wrote:Rob Dixon wrote:Clinton JAmes wrote:I wouldn't interpret "when I reach 'pears'" that literally. Alternative solution:How do I stop the parser when I reach "pears".You are presumably using HTML::TokeParser, and not Toke::Parse, Toke::Parse or
toke paser.
This should do what you want.
while (my $tag = $stream->get_tag('div')) {
next unless my $id = $tag->[1]{id};
last if $id eq 'mainbody';
}
while (my $tag = $stream->get_tag('a')) {
next unless $stream->get_trimmed_text eq 'pears';
print $tag->[1]{href}, "\n";
last;
}
while ( my $tag = $stream->get_tag ) {
if ( $tag->[0] eq 'a' ) {
print Dumper $tag;
}
last if $tag->[0] eq '/ul';
}
I assumed the OP wanted to find the first the first anchor containing 'pears'
after the first division with an id of 'mainbody'. How do you read it?
I assumed the OP wants all the anchors in the list, where the last anchor happens to contain 'pears'. At least that's what his own code indicates.
(Once again you've over-edited the previous post and no one can see what we're
taking about.)
It's a matter of taste. Everyone can view the messages by thread, just like you did. Personally I find it more annoying when people include everything in a long thread.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.
- References:
- Limiting Toke::Parser
- From: Clinton JAmes
- Re: Limiting Toke::Parser
- From: Rob Dixon
- Re: Limiting Toke::Parser
- From: Gunnar Hjalmarsson
- Re: Limiting Toke::Parser
- From: Rob Dixon
- Limiting Toke::Parser
- Prev by Date: show only numbers before, within or after the text
- Next by Date: Re: show only numbers before, within or after the text
- Previous by thread: Re: Limiting Toke::Parser
- Next by thread: Re: Limiting Toke::Parser
- Index(es):