Re: Limiting Toke::Parser
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Sat, 28 Jun 2008 13:33:29 +0100
Clinton JAmes wrote:
Hi
I'm trying to use Toke::Parse and would appreciate some advice.
My html is something like this
<div id="mainbody">
<h1>advise you to</h1>
<ul>
<li>
<a href="/Advice/apples">apples</a>
</li>
<li>
<a href="/Advice/oranges">oranges</a>
</li>
<li>
<a href="/Advice/pears">pears</a>
</li>
</ul>
<div id="footer">
<p class="style1"><span class="siteName">Smartshopper</span> is provided by the <a href="http://www.fat.gov">FatTrade</a>.</p>
<p><span class="style3 noprint">
<a href="http://fat.gov/copyright.html">Copyright</a>
<a href="http://www.fat.gov/disclaim.html">Disclaimer</a>
<a href="http://www.fat.gov/privacy.html">Privacy</a>
</span>
</p>
</div>
</div>
my toke paser snippet
while ( $tag = $stream->get_tag("div") ) {
if ($tag->[1]{id} and $tag->[1]{id} eq 'mainbody') {
while ($tag = $stream->get_tag('a')){
print Dumper $tag;
}
}
}
my problem
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;
}
Rob
.
- Follow-Ups:
- Re: Limiting Toke::Parser
- From: Gunnar Hjalmarsson
- Re: Limiting Toke::Parser
- References:
- Limiting Toke::Parser
- From: Clinton JAmes
- Limiting Toke::Parser
- Prev by Date: Re: Funky Characters in Log files
- Next by Date: Re: Using System to read mixed cased environment variables on Windows
- Previous by thread: Limiting Toke::Parser
- Next by thread: Re: Limiting Toke::Parser
- Index(es):