CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Re: [GDrew] Extracting Data from a File: Edit Log



Zhris
Enthusiast

Nov 12, 2010, 4:14 AM


Views: 2522
Re: [GDrew] Extracting Data from a File

Hi,

I'm not 100% sure on your directory structure, so the following script is only designed to process html files in a single directory. I have used HTML::TreeBuilder / HTML::Element over other modules such as HTML::HeadParser, because I prefer the level of control.

Untested:

Code
#!/usr/bin/perl     
use strict;
use warnings;
use HTML::TreeBuilder;

my $dirpath = '1.1.1 - html2010';
my @files = glob("$dirpath/*.html");

my $csv = 'output.csv';
open my $csv_fh, '>', $csv or die "cannot open $csv: $!";
foreach my $file (@files) {
my $tree = HTML::TreeBuilder->new;
$tree->parse_file($file);
my @metas = $tree->look_down("_tag", "meta");

print $csv_fh "$metas[0]->{'content'},$metas[1]->{'content'}\n";

#foreach my $meta (@metas) {
# print $csv_fh "$meta->{'content'}\n";
#}
}
close $csv_fh;


Chris


(This post was edited by Zhris on Nov 12, 2010, 4:55 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Nov 12, 2010, 4:19 AM
Post edited by Zhris (Enthusiast) on Nov 12, 2010, 4:23 AM
Post edited by Zhris (Enthusiast) on Nov 12, 2010, 4:24 AM
Post edited by Zhris (Enthusiast) on Nov 12, 2010, 4:55 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives