http://www.perlmonks.org?node_id=1186466


in reply to Re^3: Fetching table from website using HTML::TableExtract
in thread Fetching table from website using HTML::TableExtract

Hi i tried your code somewhat working but still one issue below is the output

Amount in Crores,,,,,,,,,,,,,,

Region,Level 31.03.2016,,Sanction/Renewal01.04.2016 to 28.02.2017,,,Level 28.02.2017,,Sanction/RenewalDuring Current Month,,,Level 27.03.2017,,Growthas on27.03.2017,

if you see multiple commas in first line and more than one in second row
  • Comment on Re^4: Fetching table from website using HTML::TableExtract

Replies are listed 'Best First'.
Re^5: Fetching table from website using HTML::TableExtract
by shmem (Chancellor) on Mar 30, 2017 at 09:45 UTC
    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.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      thanks it worked with first solution , when i opened it in excel ..