|< 1 2 >| | 16 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
use strict;
use warnings;
my $html = "<div id='cont'>eins<div>zwei<div>drei<div>vier</div></div></div></div>";
content($html, "cont");
print "\n";
sub content {
my $html = shift;
my $name = shift;
$html =~ m/.*?\<(.*?).*?\s+(?:id|name)\s*=\s*['"]$name['"].*?\>(.*)\<\/\1\>.*?/s;
my $tag = $1;
my $content = $2;
my $i = 0;
my ($main, $counter);
$content =~ m/(.*?)\<\/$tag\>/s;
$main = $1;
if($main =~ m/.*?\<$tag.*?\>.*?/) {
$counter = () = $content =~ m/\<$tag.*?\>/g;
} else {
$counter = () = $main =~ m/\<$tag.*?\>/g;
}
my @end = split /\<\/$tag\>/, $content;
for(0..$#end) {
if($_ == $#end-1) {
$end[$_] = $end[$_]."</$tag>";
}
}
print $counter . " mal\n";
for(0..$counter) {
print $end[$_];
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use HTML::TreeBuilder;
my $tree = HTML::TreeBuilder->new;
$tree->parse("<div id='cont'>eins<div>zwei<div>drei<div>vier</div></div></div></div>");
$tree->dump;
^Z
<html> @0 (IMPLICIT)
<head> @0.0 (IMPLICIT)
<body> @0.1 (IMPLICIT)
<div id="cont"> @0.1.0
"eins"
<div> @0.1.0.1
"zwei"
<div> @0.1.0.1.1
"drei"
<div> @0.1.0.1.1.1
"vier"
|< 1 2 >| | 16 Einträge, 2 Seiten |