Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^4: How to fetch table element from a site into data

by Anonymous Monk
on Aug 12, 2012 at 05:07 UTC ( #986935=note: print w/replies, xml ) Need Help??

in reply to Re^3: How to fetch table element from a site into data
in thread How to fetch table element from a site into data

Yes, it works! :) Can you tell me how can I put these things in a hash with key as the header and the contents as the value. So that the o/p should be like this:
$hash = { company => ('Island Trading', 'Galerφa del gastr≤nomo' +, 'Laughing Bacchus Wine Cellars', 'Paris spΘcialitΘs', 'Si +mons bistro', 'Wolski Zajazd') country => ('UK','Spain','Canada','France','Denmark','Poland') }

Replies are listed 'Best First'.
Re^5: How to fetch table element from a site into data
by Kenosis (Priest) on Aug 12, 2012 at 06:44 UTC

    One way is to populate arrays for both company and country with the elements from the dereferenced array reference ($row->[0]: company name; $row->[1]: country name), and then use those arrays to create strings (values) that will be associated with company and country keys. The script, as a whole, would then look like this:

    use Modern::Perl; use WWW::Mechanize; use HTML::TableExtract; my ( %hash, @company, @country ); my $mech = WWW::Mechanize->new(); $mech->get(''); my $html_string = $mech->content(); my $te = HTML::TableExtract->new( headers => [ ( 'Company', 'Country' +) ] ); $te->parse($html_string); for my $ts ( $te->tables ) { for my $row ( $ts->rows ) { push @company, qq|'$row->[0]'|; push @country, qq|'$row->[1]'|; } } $hash{'Company'} = '(' . ( join ', ', @company ) . ')'; $hash{'Country'} = '(' . ( join ', ', @country ) . ')'; say "$_ => $hash{$_}" for sort keys %hash


    Company => ('Island Trading', 'Galería del gastrónomo', 'Laughing Bacc +hus Wine Cellars', 'Paris spécialités', 'Simons bistro', 'Wolski Zaja +zd') Country => ('UK', 'Spain', 'Canada', 'France', 'Denmark', 'Poland')

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986935]
[Corion]: marto: Redoing something on new infrastructure sounds fun. At least you can reuse your previous experience :)
[marto]: I'm looking forwads to it. The video sources are dying, and they don't have the hardware to play them back (old tape formats, not just VHS + Laserdisc etc)
[marto]: I'll be interested to see what difference in terms of file size/quality the new codecs make. I enjoy working on things like this, so that's a bonus
[Corion]: Ah, cool! So it's not an inhouse youtube but for a wider consumption
[marto]: last time it was IE6 clients, now they're on 11, so more scope there also, in terms of UI and playback

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-07-28 09:17 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (425 votes). Check out past polls.