Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: regexp text parsing issue.

by holli (Abbot)
on Mar 19, 2005 at 09:51 UTC ( [id://440894]=note: print w/replies, xml ) Need Help??


in reply to regexp text parsing issue.

Of course you can use HTML::Parser and code the table parsing by hand, but I suggest using HTML::TableContentParser, which is a subclass of HTML::Parser:
use strict; use HTML::TableContentParser; my $html = qq{ <table> <tr><td>1</td><td>2</td><td>3</td></tr> <tr><td>4</td><td>5</td><td>6</td></tr> <tr><td>7</td><td>8</td><td>9</td></tr> </table> <table> <tr><td>11</td><td>12</td><td>13</td></tr> <tr><td>14</td><td>15</td><td>16</td></tr> <tr><td>17</td><td>18</td><td>19</td></tr> </table> }; my $p = HTML::TableContentParser->new(); my $tables = $p->parse($html); for my $table (@$tables) { print "new table!\n"; for my $row (@{$table->{rows}}) { print "new row: "; for my $column (@{$row->{cells}}) { print "[$column->{data}] "; } print "\n"; } }
That prints:
new table! new row: [1] [2] [3] new row: [4] [5] [6] new row: [7] [8] [9] new table! new row: [11] [12] [13] new row: [14] [15] [16] new row: [17] [18] [19]
Easy, nice, reliable and clean. Enjoy! ;-)


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: regexp text parsing issue.
by sh1tn (Priest) on Mar 19, 2005 at 09:57 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://440894]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found