in reply to Re^4: Fetching table from website using HTML::TableExtract
in thread Fetching table from website using HTML::TableExtract
if you see multiple commas in first line and more than one in second row
What do you expect?
You are basically outputting a CSV file in which each line has the same amount of fields, separated by commas. Nothing between two commas is an empty field produced by expanding field spanning captions of the original table denoted as e.g. colspan="2" in html.
If those fields were omitted, the placement of the captions would not correspond to the columns of the table data. Load the output file as a spreadsheet (e.g. in Excel) and you will see the effect.
I don't know the purpose of what you are doing. If you want to remove empty fields from the output, proceed as follows:
foreach my $ts ( $te->tables ) { print "Table (", join( ',', $ts->coords ), "):\n"; foreach my $row ( $ts->rows ) { s/[\s\n]+\z/ for @$row; s/\n/ /gs for @$row; $OUT-> print( join( ',', grep { length $_ } @$row ), "\n"); } }
Again, load the data into a spreadsheet to see the difference. Compare to the original table on the website.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Fetching table from website using HTML::TableExtract
by sachin raj aryan (Sexton) on Mar 30, 2017 at 11:54 UTC |