in reply to Re: Parsing and converting HTML
in thread Parsing and converting HTML

Hello, thanks but for some reason this did not seem to work. Though it is probably something I am doing wrong.

here is my code

#!c:/strawberry/perl/bin/perl.exe use HTML::TokeParser; use HTML::Element; use HTML::TreeBuilder; use warnings; open(MYINPUTFILE, '<C:\acs\SA\content\acs\meetings\expositions\CNBP_ +028491'); while(<MYINPUTFILE>) { my $text = $_; my $html = HTML::TreeBuilder->new_from_content("$text") || die "$@\n +"; sub to_text { if (ref $_[0] eq "HTML::Element") { foreach my $sub_element ($_[0]->content_list) { &to_text($sub_element); } } else { print qq{text="$_[0]"}; } } &to_text($html); }

any other thoughts or did I miss something? Thanks again

Replies are listed 'Best First'.
Re^3: Parsing and converting HTML
by aitap (Curate) on Jul 27, 2012 at 07:28 UTC
    You are trying to parse your file by line. Every line an HTML::Element object gets created and then destroyed. You can use new_from_file HTML::TreeBuilder method instead.
    Sorry if my advice was wrong.
Re^3: Parsing and converting HTML
by Anonymous Monk on Jul 26, 2012 at 23:59 UTC
    my $tree = HTML::TreeBuilder->new;
    $tree->parse_file( $filename );
    ...