我将下载的 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