hi!,
I'm trying to parse this html using html tokerparser.
HTML:
<div class="text12">This text I don't need.</div>
<div class="text12">This long test that is at least 201 characters in
+length is what I want to parse.
<br><br>
Here is a list that I want to retrieve in this "div" tag.<br>
List:<br>
<li>item 1
<li>item 2
<li>item 4
<div>
Now since, I don't want to retrieve both div tags, i'll use a if command to check if the character length is at least 200.
Now my problem is when I use the below code, I retrieve the text only , but not the HTML, therefore leaving out the
<li> tags and giving me spaces. Once retrieving the value, I can't really do anything to format the text I retrieved to a HTML list.
Is there anyway to work around this? Perhaps another command that allows Tokerparser to retrieve the HTML tags withing the 'div' tags rather then ignorning them.
my coding:
while( $token = $stream->get_token) {
if ($token->[0] eq 'S' and $token->[1] eq 'div' and ($token->[2]{'clas
+s'} || '') eq 'text12') {
$description = $stream->get_trimmed_text('/div');
$num = length($description);
if ($num > 200) {
print "$description<br><br>";
}
}
}
the above just prints out the text that turns out to look like this:
#description value:
Here is a list that I want to retrieve in this "div" tag.
List:item 1 item 2 item 4
#I want to take the description value and print it out as HTML but sin
+ce the <li> tags aren't entact, I can't properly display the list in
+a browser.
Thanks!
Tanger
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.