Thread URI: Relative URI auflösen (23 answers)
Opened by GwenDragon at 2010-07-02 16:32

GwenDragon
 2010-07-02 16:32
#139327 #139327
User since
2005-01-17
14555 Artikel
Admin1
[Homepage]
user image
Ich plage mich gerade mit einem Problem. Ich muss HTML parsen und Links umwandeln. Parsen ist ja kein Problem mit HTML::Parser.

Es sollen gefundene relative Links in absolute umgewandelt werden.
Will URI aber nicht wirklich und immer. :(

Kann mir das jemand erklären und einen Ausweg aus dem Problem sagen?

Testschnippsel:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/perl

use strict;
use warnings;

use URI;

my $myurl = 'http://example.org/a/b/c/d/e/y.html';

print "BasisUrl = $myurl\n\n";

for my $u ( 
        'http://example.org/x/../../../../../x.htm', 
        '../../../../../x.htm',
        '../x.htm',
        '././../././../../x.htm',
        '././../././../.././../.././../.././../../../x.htm'
) {
        print "$u = ", URI->new_abs($u, $myurl), "\n";
}


Ausgabe:
Code: (dl )
1
2
3
4
5
6
7
BasisUrl = http://example.org/a/b/c/d/e/y.html

http://example.org/x/../../../../../x.htm = http://example.org/x/../../../../../x.htm
../../../../../x.htm = http://example.org/x.htm
../x.htm = http://example.org/a/b/c/d/x.htm
././../././../../x.htm = http://example.org/a/b/x.htm
././../././../.././../.././../.././../../../x.htm = http://example.org/../../../../../x.htm


Mag ja am Wetter liegen, 32°C, aber ich stehe auf dem Schlauch.

//EDIT: Defekte Tags repariert
Last edited: 2010-07-02 16:34:49 +0200 (CEST)
die Drachin, Gwendolyn


Unterschiedliche Perl-Versionen auf Windows (fast wie perlbrew) • Meine Perl-Artikel

View full thread URI: Relative URI auflösen