#!/usr/bin/perl -w use strict; require HTML::TreeBuilder; my $tree = HTML::TreeBuilder->new; # empty tree $tree->parse($_) while <DATA>; $tree->eof; $tree->elementify(); # Looking for # <meta http-equiv=Content-Type content="text/html; charset=windows-12 +52"> my $content_type = $tree->look_down( '_tag', 'meta', sub { my $elem = shift; $elem->attr('http-equiv') eq 'Content-Type'; } ); print $content_type->attr('content'), "\n"; __DATA__ <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=windows-1252 +"> <meta name=ProgId content=Word.Document> <meta name=Generator content="Microsoft Word 14"> <meta name=Originator content="Microsoft Word 14"> <link rel=File-List href="junk_files/filelist.xml"> <link rel=themeData href="junk_files/themedata.thmx"> <link rel=colorSchemeMapping href="junk_files/colorschememapping.xml"> </head> <body lang=EN-US style='tab-interval:.5in'> <div class=WordSection1> <p class=MsoNormal>This is some text</p> </div> </body> </html>
In reply to Re: HTML parsing module handles known and unknown encoding
by kennethk
in thread HTML parsing module handles known and unknown encoding
by ambrus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |