#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use URI::URL;
my $VERSION = 0.1;
my (
$title,
$content,
$url,
);
$title = "HTML Table Fixer";
print "Content-type: text/html\n\n";
unless ($url = $ENV{PATH_INFO}) {
print "This program will present you an HTML document
with its TABLE and TD tags stripped of absolute
widths. Call this URL again, and append the URL of the
desired document\n";
exit;
}
for ($url) {
s,^/(?=[^/]),//,;
s,^/*http:,,i;
if ( /^(\w+):/ ) {
if ( "\U$1" ne "HTTP") {
print "
Error
", "Bad URL:",
"You must specify an http URL only\n";
exit;
}
} else {
s/^/http:/;
}
}
my $ua = new LWP::UserAgent;
$ua->agent("$0/$VERSION " . $ua->agent);
my $req = HTTP::Request->new(GET => $url);
$req->header('Accept' => 'text/html');
# send request
my $res = $ua->request($req);
# check the outcome
if ($res->is_success) {
$content = $res->content;
} else {
print ("Error
");
print "Can't fetch $url: ", $res->code, " ", $res->message;
exit;
}
my $u = URI::URL->new($url);
my ($site, $prepath);
$site = $u->host();
($prepath = $url) =~ s,/[^/]*$,,;
for ($content) {
if ($url =~ /\bcnn\b/) {
s{]*search.and.promos.*?(?=]*search\s+-\s+replace.*?/search.*?>}{}gsi;
s{