relative to absolute Hyperlink-URL 
Author Message
 relative to absolute Hyperlink-URL

Hello,
I want to exchange relative URLs in a HTML-Document into absolute.
I have written a regular expression, but I don't know, wether I have
all cases that can happen.

It would be nice, if somebody makes a review.

I have also problems to use the HTML::Parser,TreeBuilder...-Modules.
All books have the same 3 examples. Does somebody know a good
describtion.

Thanks,
Andreas
-----------------------------------------------
href=bla.gif --> href=path/bla.gif
href = "bla.gif"  -->  href="path/bla.gif"
href = http://www.*-*-*.com/ ;(absolute URL) --> href
= http://www.*-*-*.com/

src  = "bla.gif"  --> src="path/bla.gif"

sub absoluter_Pfad_in_href
{
        my $absoluterPfad=shift;
        my $HTMLText=shift;
        $HTMLText =~
s/(src|href)\s*=\s*(\"?)(?!(http:\/\/|mailto))(.*?)>/\1=\2$absoluterPfad\4>/gi;
#       s       search
#       (src|href)      src or href
#       \s*     no or more space
#       =
#       \s*     no or more space
#       (\"?)      no or one "
#       (?!(http:\/\/|mailto))          if http:// oder mailto, no change
#       (.*?)  
#       >    Tagend
        return $HTMLText;

Quote:
}



Wed, 18 Jun 1902 08:00:00 GMT  
 relative to absolute Hyperlink-URL

Andreas> Hello,
Andreas> I want to exchange relative URLs in a HTML-Document into absolute.
Andreas> I have written a regular expression, but I don't know, wether I have
Andreas> all cases that can happen.

Andreas> It would be nice, if somebody makes a review.

A regex cannot catch them properly.  It'd be better to use
HTML::LinkExtor: that's even one the examples on the manpage.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095

Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. relative to absolute Hyperlink-URL

2. relative to absolute Hyperlink-URL

3. Relative and Absolute URL's: Parsing

4. Absolute newbie question regarding hyperlinks and WML

5. Convert absolute path to relative

6. HTTP::Request, FTPs, Relative vs Absolute Directory

7. LWP::Simple - relative or absolute path?

8. relative to absolute path expansion

9. filter of absolute urls to relative urls?

10. Converting relative to absolute path

11. I want $0 to give me an absolute path name instead of relative

12. Absolute or Relative paths?

 

 
Powered by phpBB® Forum Software