#!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 output directories.\n\n"; print "Example of use: htmlParser-V.1.0.pl \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 create 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_Label2"); 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;