Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: converting absolute to relative links

by repson (Chaplain)
on Feb 03, 2001 at 10:52 UTC ( [id://56211]=note: print w/replies, xml ) Need Help??


in reply to converting absolute to relative links

The main wheels I would suggest would be HTML::Parser or any of several others in the HTML:: tree, and URI.

use URI; use HTML::Parser; my $parse = new HTML::Parser( default_h => [ sub {print shift}, 'text' + ], start_h => [ sub { my ($tag, $attr, $origtext) = @_; if (($tag eq 'img') and ($attr->{src} =~ m#^(?:http://)?myserver\. +#)) { $attr->{img} = URI->new($attr->{img})->abs('http://myserver.com' +); print "<$tag " . join (' ', map {$_.'="' . $attr->{$_} . '"'} ke +ys %$attr) . '>'; } else { print $origtext; } }, "tagname, attr, text"] ); $parse->parse(join('',<>));
However this code is untested and may well need some work. It currently would take input on STDIN and produce results on STDOUT.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://56211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-19 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found