Deleting images using libwww-perl

whetzel@grok82.columbiasc.ncr.com
Thu, 8 Aug 1996 09:13:58 -0400


To all,
   I'm a new convert to the libwww-perl package and I was hoping more
experienced users could give me a hand. I've checked the mailing list
archive and the documentation but haven't had much luck getting the
answer I need. Essentially, I'm trying to selectively delete images
from an HTML file. I'm trying something similar to the following (based
in part on a previous example posted to this list:


-----------
%link_elements =
  (
   'img'  => 'remove',
  );

use HTML::Element;
use HTML::Parse;

my $page = parse_htmlfile("test.html");
$page->traverse(sub {
     			my($ele,$flag,$depth) = @_;
                        my $attr = $link_elements{$ele->tag};
                        if (defined $attr) {
                            $ele->delete;
                            return 1;
                        }
                        1;
                    }, 1);

    $htmlstr = $page->asHTML;
    $page->delete;
    print $htmlstr;
-----------

When I actually print the HTML, though, the images are still there, though
some debugging I've done shows the delete command is supposedly being 
executed. I'm assuming that I'm just not understanding the HTML tree
that's getting built and modified. Does anyone have any ideas on how
to make this work? Any help would be greatly appreciated!

Thanks!
John Whetzel

-- 

 _____________________________________________________________________
|John Whetzel			    | 2 rules to success in life:     |
|john.whetzel@ColumbiaSC.ATTGIS.COM |                                 |
|AT&T Global Information Solutions  | 1. Don't tell people everything | 
|Phone: (803) 939-2055              |          you know.              | 
|Fax:   (803) 939-7317              |                                 |
|__________________________________ |_________________________________|