0

ダウンロードした HTML を STDIN に渡し、テーブル マークアップ以外のすべてのタグを削除しています。table、tr、および td の残りのインスタンスに基づいてテーブルをレンダリングしたいので、テーブルは "\t" または "|" になります。区切られています。ASCII 形式のテーブルも機能します。以下は私がこれまでに持っているものですが、それは仕事を成し遂げません:

#!/usr/bin/perl -ws
use HTML::Scrubber;
use HTML::Entities qw(decode_entities);
use Text::Unidecode qw(unidecode);

my $HTMLinput = do {local $/; <STDIN>};

my $scrubber = HTML::Scrubber->new( allow => [ qw[ table tr td ] ] );

#this prints the text from the page, but without formatting tables in ASCII:
#print $scrubber->scrub($HTMLinput);

my $scrubber2 = $scrubber->scrub($HTMLinput);

#was hoping this would remove transform table, tr, and td-tagged content
#into ASCII-formatted tables, but it doesn't work:
print unidecode(decode_entities($scrubber2)), "\n";

#test page: http://www.w3schools.com/html/html_tables.asp
#curl http://www.w3schools.com/html/html_tables.asp | html.table.parser.pl 
4

2 に答える 2

1

ユーザー名tjdのおかげで、私がたどり着いた解決策は次のとおりです。

#!/usr/bin/perl -ws
use HTML::Scrubber;

my $HTMLinput = do {local $/; <STDIN>};
my $scrubber = HTML::Scrubber->new( allow => [ qw[ table tr td ] ] );
print $scrubber->scrub($HTMLinput);

#test page: http://www.w3schools.com/html/html_tables.asp
#links -dump http://www.w3schools.com/html/html_tables.asp | html.table.parser.pl 

#needed: "links" program for bash (sudo yum install links)
#http://www.jikos.cz/~mikulas/links/
于 2013-06-04T15:19:39.360 に答える
0

テキストで表を作成する車輪を再発明したくありません。linksまたはのようなテキストブラウザの出力をw3mファイル/標準出力にパイプするか、モジュールのようなものを使用Text::Tableして重い仕事をします。

于 2013-06-04T19:30:17.513 に答える