]> git.nbdom.net Git - nb.git/commitdiff
html2txt(): use html_unescape on return text
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 16 Apr 2023 21:17:07 +0000 (23:17 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 16 Apr 2023 21:17:07 +0000 (23:17 +0200)
bin/html2csv
lib/perl/NB/Functions.pm

index 5709044e7acf83597bd562dda8df379c5f610b56..a33676620dab56028c206d86e0adcc8637b835f6 100755 (executable)
@@ -74,7 +74,8 @@ my $exp1 = $Opt{exp1}; $exp1 and $exp1 = "[^>]*$exp1";
 my $exp2 = $Opt{exp2}; $exp2 and $exp2 = "[^>]*$exp2";
 my $exp3 = $Opt{exp3}; $exp3 and $exp3 = "[^>]*$exp3";
 
-for my $table ($html =~ m,<${T1}${exp1}[^>]*>(.*?)<\s*/\s*${T1}\s*>,gi) {
+for my $table ($html =~ m,<${T1}${exp1}[^>]*>(.*?)<\s*/\s*${T1}\s*>,gi)
+{
   $table_num++;
   #warn $table_num;
   next if defined $Opt{'num'} and $Opt{num} and $Opt{num} != $table_num;
@@ -86,14 +87,17 @@ for my $table ($html =~ m,<${T1}${exp1}[^>]*>(.*?)<\s*/\s*${T1}\s*>,gi) {
 
        $tr = "<>$tr</>" unless $T3;
        my $count = 0;
-    for my $td ($tr =~ m,<${T3}${exp3}[^>]*>(.*?)<\s*/\s*${T3}\s*>,gi) {
+    for my $td ($tr =~ m,<${T3}${exp3}[^>]*>(.*?)<\s*/\s*${T3}\s*>,gi)
+    {
       $td = html2txt($td) unless $Opt{html};
       $_ = chr(194).chr(160); $td =~ s/$_/ /g;
       $td =~ s/\s+/ /g;
       $td = str_trim($td);
       $count++;
+
       push(@col,$td);
-      if (1 and $COUNT and $count > $COUNT) {
+      if ($COUNT and $count > $COUNT)
+      {
                print join($Opt{sep},@col)."\n";
                @col = ();
       }
@@ -201,7 +205,7 @@ __DATA__
 
 =head1 NAME
 
-$NAME - Script to extract html table into csv
+$NAME - Script to print html table into csv
 
 =head1 SYNOPSIS
 
index cd3a0a69b8a602ef7f49e9f17e9c92bd82ecfc9a..9e94d0da21f8991425e0f4e82018d4bf72c0ba10 100644 (file)
@@ -529,7 +529,7 @@ return $db;
 
 sub html2txt {
 
-my $v = shift @_;
+       my $v = shift @_;
 
   # New line
        $v =~ s,
@@ -561,6 +561,7 @@ my $v = shift @_;
 
        $v =~ s/[\f ]+/ /g;
        &str_trim($v);
+       $v = &NB::Functions::html_unescape($v);
 
        return $v;