Created
August 18, 2016 07:12
-
-
Save m0veax/1a7d3e20f33cbc689f27a9dc35969042 to your computer and use it in GitHub Desktop.
create csv output from the first found table with tbody in a html document string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use DDP; | |
use FindBin qw/$Bin/; | |
use lib "$Bin/../lib"; | |
use Mojo::DOM; | |
use Path::Tiny; | |
my $html = path(shift)->slurp; | |
my $dom = Mojo::DOM->new($html); | |
my $table = $dom->find("table > tbody")->first; | |
my $rows = $table->children("tr"); | |
my $data_table = []; | |
for my $tr (@$rows) { | |
my $cells = $tr->children("td"); | |
my $values = []; | |
for my $td ( @$cells ) { | |
my $text = $td->all_text; | |
$text =~ s/^\s+|\s+$//g; | |
$text =~ s/\n/\,/g; | |
push @$values, $text; | |
} | |
print join(";", @$values) . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment