Hello, I need to extract Arabic text from HTML files. However, some files worked well, while the others I get non-readable characters like "العام". Here, is my code:

#!C:/STRAWB~1/perl/bin/perl.exe -w use Data::Dumper; use HTML::TreeBuilder; use HTML::TreeBuilder::XPath; use utf8; #------------------------------------------ if (!$ARGV[0] || !$ARGV[1]) { print "\n\n htmlParser-V.1.0.pl: Error: missing input and/or outpu +t directories.\n\n"; print "Example of use: htmlParser-V.1.0.pl <input-path> <output-pa +th>\n\n"; exit; } my $inputpath = $ARGV[0]; my $outputpath = $ARGV[1]; #================# Read the files from the inputpath opendir(DIR, $inputpath) || die "\n - ERROR: Can't open the input path +: '$inputpath' !!"; my @files = grep { -f "$inputpath/$_" } readdir(DIR); closedir DIR; #================# First, check if outputpath exists. If not, we creat +e it. if (not -e $outputpath){ mkdir $outputpath; print "\n - Output path created!"; } #===================================================================== +=====# foreach $file (@files){ open (FILE, '<:encoding(UTF-8)', "$inputpath/$file") || die "can't +openfile $file: $!"; print "\n - Scanning file '$file' ... "; my $root = HTML::TreeBuilder->new_from_file("$inputpath/$file"); $root->parse("$inputpath/$file"); #=======First Attribute======== my @div_class = $root->find_by_attribute("id","maincontent"); #_by_attribute("id","ctl00_ContentPlaceHolder1_FormView1_Label +2"); foreach my $node (@div_class) { open (OUT,">>$outputpath/Bank\-$inputpath\-$file\.txt") || die +("\n - ERROR: Can't create the output file !!"); print OUT $node->as_text, "\n"; print OUT "\n"; }###foreach }#foreach print "OK"; close FILE; close OUT;


In reply to Arabic Encodding Problem by malak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.