morgon has asked for the wisdom of the Perl Monks concerning the following question:
I have collection of spanish-language html-files that I want to convert into a plucker document.
But before I can do that I need to get rid of some crap that the files contain, so I parse them, extract the things I want and create a new html-file containing just the extracted bits.
The files I start with are utf8-encoded and claim (in the DOCTYPE) to be xhtml, but they don't validate (missing closing tags - oh well) so I use HMTL::TreeBuilder::XPath for parsing.
Now the thing is that the source-documents do not use any html-entities but contain the spanish special characters as (2 bytes) utf-characters. And this is where I have a problem.
Here my code (which works apart from the problem below):
What happens now is that e.g. the spanish character ú that is encoded as hex c3ba in the source document gets transformed into ú (i.e. ú) in the output - and that is wrong...use strict; use HTML::TreeBuilder::XPath; my $tree = HTML::TreeBuilder::XPath->new; $tree->parse_file("in.html"); my ($tit) = $tree->findnodes(q{/html//h1[@class='title']}); my ($sub) = $tree->findnodes(q{/html//div[@class='submitted']}); my ($aut) = $tree->findnodes(q{/html//div[@class='autor']}); my ($art) = $tree->findnodes(q{/html//div[@class='content clear-block' +]}); my ($nav) = $tree->findnodes(q{/html//div[@class='book-navigation']}); $nav->detach; my (@childs, undef, undef) = $art->content_list; open my $fh, ">", "out.html" or die $!; print $fh "<html><body>" . join("\n", map { $_->as_HTML } ($tit, $sub, $aut, $art) +) . "</body></html>";
Does someone have an idea on how to fix this?
Many thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: transforming html
by muba (Priest) on Sep 29, 2010 at 01:44 UTC | |
by morgon (Priest) on Sep 29, 2010 at 02:01 UTC | |
by muba (Priest) on Sep 29, 2010 at 02:35 UTC | |
by morgon (Priest) on Sep 29, 2010 at 21:07 UTC | |
by muba (Priest) on Sep 29, 2010 at 23:21 UTC | |
|
Re: transforming html
by salmonix (Initiate) on Sep 29, 2010 at 10:10 UTC |