Last active
January 17, 2016 15:59
-
-
Save yakovsh/6b9c880d0d132788f269 to your computer and use it in GitHub Desktop.
Cleaning Up Bad HTML in Perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Here is a short way to cleanup bad HTML input and convert to XML with Perl: | |
# | |
use HTML::TreeBuilder; | |
use XML::LibXML; | |
$html_code = ''; | |
my $builder = HTML::TreeBuilder->new(); | |
$xml_source = $builder->parse($html_code); | |
$xml_source->elementify(); | |
$xml_source1 = $xml_source->as_XML(); | |
my $parser = XML::LibXML->new(); | |
$parser->recover(1); | |
my $doc = $parser->parse_string($xml_source1); | |
$xml_source2 = $doc->toString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment