use LWP::UserAgent; use URI; my $response = LWP::UserAgent->new->get('http://search.cpan.org/'); $html = $response->content; $base = $response->base; # RegEx converts all links in $html to absolute URLs $html =~ s/<(.*?)(href|src|action|background)\s*=\s*("|'?)(.*?)\3((\s+ +.*?)*)>/"<".$1.$2."=\"".URI->new_abs($4,$base)->as_string."\"".$5.">" +/eigs; print $html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Convert Relative to Absolute URLs on-the-fly
by merlyn (Sage) on Feb 06, 2008 at 16:44 UTC | |
by Tanktalus (Canon) on Feb 06, 2008 at 21:40 UTC | |
by merlyn (Sage) on Feb 06, 2008 at 22:21 UTC | |
by nikhil.patil (Sexton) on Feb 07, 2008 at 07:26 UTC | |
by merlyn (Sage) on Feb 07, 2008 at 15:10 UTC | |
|
Re: Convert Relative to Absolute URLs on-the-fly
by sids (Acolyte) on Feb 08, 2008 at 04:03 UTC | |
by mjlush (Novice) on May 18, 2009 at 11:15 UTC |