[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changing relative links to absolute
Eric,
Since this is a common problem to solve, there are several excellent utilities
that already do this. Two programs that do this that I am familiar with are
w3mir and lwp-rget. Both of these are written in Perl, and available from the
CPAN. If they do not do exactly what you want, it is easy enough to tear into
the source and change it around.
Good luck,
-Colin.
On Tue, Feb 08, 2000 at 09:55:41AM -0500, ERIC STEDFELD wrote:
> I'm having a dumb substitution problem--perhaps someone can catch my
> error, or show me a better way?
>
> I created a first script to connect to a remote Web page, based on
> input from several sources, but unfortunately the page that I'm
> connecting to has relative links for displaying graphics, relative
> links to other pages, etc. These display as broken links in the page
> that my script returns to the user. I'm trying to do a few
> substitutions in my script, to change the relative links to absolute
> in the page that is returned to the user, but I'm afraid perhaps the
> syntax of the regular expression may be escaping me (unless I'm just
> plain doing this wrong). Here is the relevant section:
>
> ...
>
> if ($resp->is_success) {
> # change relative links to absolute
> $resp =~ s:src\=\"/:src\=\"http\://www.server.nyu.edu/:gi;
> $resp =~ s:href\=\"/:href\=\"http\://www.server.nyu.edu/:gi;
> print $resp->headers_as_string()."\n\n";
> print $resp->content;
> } else {
> print $resp->error_as_HTML;
> }
>
> ...
>
> I used : instead of slashes for my regex delimiters, to make them
> stand out better and to cut down on the \/\/\/ stuff--of course, then
> I had to escape the : in "http:". Thing is, the substitution wasn't
> working when I used traditional slashes either. I don't generate an
> error when I run the script--it just doesn't change the links on the
> page from relative to absolute, the way I want it to!
>
> Thanks for any "nudge" anyone can give me in the right direction,
>
> --Eric
>
>
> =====================
> Eric L. Stedfeld
> Info Tech Specialist
> NYU Libraries
> 212 995-3545
> eric.stedfeld@nyu.edu