Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^5: Fetching table from website using HTML::TableExtract

by shmem (Chancellor)
on Mar 30, 2017 at 09:45 UTC ( #1186470=note: print w/replies, xml ) Need Help??


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.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^6: Fetching table from website using HTML::TableExtract
by sachin raj aryan (Acolyte) on Mar 30, 2017 at 11:54 UTC
    thanks it worked with first solution , when i opened it in excel ..

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2022-05-28 16:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (99 votes). Check out past polls.

    Notices?