in reply to Grabbing a Web Page and Replace Variables

A lot of people have been trying to munge html with regexes lately. HTML::Filter gives you a lot more power. I like using something like this, sweeten to taste:
package MyFilter; use HTML::Filter; use vars qw( @ISA ); @ISA = qw( HTML::Filter ); sub start { my ($self, $tag, $attrs, $attrseq, $origtext) = @_; my $rewrite; if (exists $attrs->{src}) { $attrs->{src} = "http://foo.bar.com/$attrs->{src}"; $rewrite = 1; } if (exists $attrs->{href}) { $attrs->{href} = "http://foo.bar.com/$attrs->{href}"; $rewrite = 1; } if ($rewrite) { print "<$tag"; foreach my $attr (@$attrseq) { print qq[ $attr="$attrs->{$attr}"]; } print ">"; } else { print $origtext } } package main; my $filter = MyFilter->new(); $filter->parse($html); $filter->eof();

Replies are listed 'Best First'.
Re: Re: Grabbing a Web Page and Replace Variables
by LostS (Friar) on May 05, 2001 at 00:01 UTC
    That is great... however I am having my script go to the web on a totally seperate server grap a web page and then parse it... it is a a $webpage variable.