in reply to Image Size in an HTML file

I think the best way to parse the HTML files is with HTML::Parser.

This snippet will extract the src attributes any img tags that are found:

use strict; use IO::File; use HTML::Parser; # version 3.15, by the way # get the contents of the HTML file my $fh = new IO::File('google.html'); my $html = do {local $/; <$fh>}; my $parser = HTML::Parser->new(api_version => 3); $parser->handler(start => \&start, 'self,tagname,attr'); $parser->parse($html); sub start { my ($parser,$tag,$attr) = @_; return unless $tag eq 'img'; # insert code to process the image file print $attr->{src}, "\n"; }
From here you can add code to open the image file, and for the fun part, insert the new value in . . .

Jeff

R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--

Replies are listed 'Best First'.
Re: (jeffa) Re: Image Size in an HTML file
by Stamp_Guy (Monk) on Jun 02, 2001 at 20:25 UTC
    Hey Jeffa,
    Thanks for the code snippet. I tried running it though and I got this error: "Can't locate object method "handler" via package "HTML::Parser" at parser.pl line 14 <GEN0> chunk 1". Any idea what's wrong?

    -Stamp_Guy