I have an html file “statistics.htm”. Got the data in the html file to a variable.
suppose in the variable i have below data:
<ul class="chart-legend">
<li class="label-1">
<div><em></em>FTP<br>
0 B</div>
</li>
<li class="label-2">
<div><em></em>HTTP<br>
589 KB</div>
</li>
<li class="label-3">
<div><em></em>POP3/IMAP<br>
0 B</div>
</li>
<li class="label-4">
<div><em></em>SMTP<br>
0 B</div>
</li>
</ul>
suppose if customer gives FTP as an argument i want the FTP value which is 0 B in above case.
How can i achieve this?
You can do this very simply with HTML::TreeBuilder::XPath (OK, very simply until you get to the fun XPath query!):
The XPath expression: look for a
brin adiv, one which previous sibling text is'FTB'(you may want to normalize spaces there). Then take the next sibling text. Wrap this in anormalize-spaceto clean-up the result, Voilà!