Skip to content

Instantly share code, notes, and snippets.

@sfoster
Created June 10, 2011 00:56
Show Gist options
  • Save sfoster/1018071 to your computer and use it in GitHub Desktop.
Save sfoster/1018071 to your computer and use it in GitHub Desktop.
perl script to extract tab delimited entries from Firebug's ConsoleExport html output
#!/usr/bin/perl
# quick, throwaway script to extract out info messages from the HTML dump of the
# firebug console which is produced by the ConsoleExport Firefox/Firebug
# plugin.
# I was interested in info message of the form.. so its pretty specific
# console.info("some label:87ms", 113, 200);
# TODO provide a way to extract log/warn/info/error/all entry types
use strict;
use HTML::Parser ();
use File::Slurp ();
use Cwd;
use Data::Dumper;
my $usage = "$0 filename.html";
my $flag = 0;
my $innerFlag = 0;
my @stack = ();
my $msgs = [];
sub start {
my ($tag, $attr) = @_;
if($attr->{'class'} && $attr->{'class'} =~ /\blogRow-info/) {
$flag = 1;
@stack = ();
push(@$msgs, "");
}
if($flag) {
push @stack, $tag;
if($attr->{'class'} && $attr->{'class'} =~ /\bobjectBox-text/) {
$innerFlag = 1;
}
}
}
sub text {
my ($str) = @_;
if($innerFlag && $str =~/\S/) {
my $msg = pop @$msgs;
$msg .= $str;
push (@$msgs, $msg);
# print(Dumper(\@_), "\n");
}
}
sub end {
if($flag) {
pop @stack;
unless(scalar(@stack)){
$flag = 0;
}
}
$innerFlag = 0;
}
sub entry {
shift;
s/\b:?(\d+)(ms)?/\t$1/;
if(/\t\d/) {
print $_, "\n";
}
}
my $p = HTML::Parser->new(
api_version => 3,
start_h => [\&start, "tagname, attr"],
text_h => [\&text, "dtext"],
end_h => [\&end, "tagname"],
unbroken_text => 1
);
my $cwd = cwd();
my $filename = $cwd ."/". shift @ARGV;
unless(-T $filename) {
warn "No such file at: $filename\n";
die $usage . "\n";
}
warn "parsing file: " . $filename;
if($p->parse_file($filename)) {
foreach(@$msgs) {
s/^\s+//;
s/\s+$//;
entry($_);
}
warn "Done\n";
} else {
warn "Error parsing: $!\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment