turning relative into absolute urls

F

Felix

Hi -

I need a perl function ("make_absolute")that turns all relative URLs
in an html document into absolute URLs, using the URL from which the
document was fetched as an argument (see script below), and then
returns the updated, entire html document.

I fiddled with Perl classes like URI and HTML:parsner but wasn't able
to get it right. Thanks a bunch.

#script:

$content = get ($url);
$content = &make_absolute ($content, $url);

print $content; exit;

sub make_absolute {

# need code here

}
 
G

gnari

Felix said:
Hi -

I need a perl function ("make_absolute")that turns all relative URLs
in an html document into absolute URLs, using the URL from which the
document was fetched as an argument (see script below), and then
returns the updated, entire html document.

I fiddled with Perl classes like URI and HTML:parsner but wasn't able
to get it right. Thanks a bunch.

I think it would be more productive, if you told us in what way you
were not able to get it right with these. I am sure a lot of people here
will gladly (gleefully, even) point out what you are doing wrong.

do you need a general solution working with any valid HTML,
or is the HTML structure a known and simple structure, that
regexes would be able to handle?

gnari
 
T

Tore Aursand

I need a perl function ("make_absolute")that turns all relative URLs
in an html document into absolute URLs, using the URL from which the
document was fetched as an argument (see script below), and then
returns the updated, entire html document.

perldoc HTML::LinkExtor


--
Tore Aursand <[email protected]>
"Omit needless words. Vigorous writing is concise. A sentence should
contain no unnecessary words, a paragraph no unnecessary sentences,
for the same reason that a drawing should have no unnecessary lines
and a machine no unnecessary parts." -- William Strunk Jr.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top