in reply to replace relative links with absolute links

I would suggest using HTML::Parser to extract the relative URLs, and then use the URI module to change them into absolute (see the abs() method)
  • Comment on Re: replace relative links with absolute links

Replies are listed 'Best First'.
Re: Re: replace relative links with absolute links
by Anonymous Monk on Jan 06, 2003 at 20:51 UTC
    Good idea. can also use the

    HTML::LinkExtor
    URI::URL

    modules. simple example:

    #!/usr/bin/perl -w use strict; my @imgs; my $lx = HTML::LinkExtor->new(\&img); my $respond = LWP::UserAgent->new->request(HTTP::Request->new(GET => ' +http://www.ibm.com')); my $base = $respond->base; $lx->parse($respond->content); for(@imgs){ print "Relative: $_\n"; print "Full: ",url($_,$base)->abs,"\n\n"; } sub img{ my($tag,%links) = @_; push(@imgs,values %links) if($tag eq 'img'); }
      HTML::LinkExtor is for extracting links, not altering HTML content. It's definetly the wrong tool for this job. HTML::Parser or HTML::TokeParser::Simple is what you'd wanna use here.

      update: here are some relevant links


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      ** The Third rule of perl club is a statement of fact: pod is sexy.