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
<table>
<tbody>
<tr>
<td>
<div>
Alter:
<br>
Wohnort:
<br>
Haarfarbe:
<br>
Figur:
<br>
Gewicht:
<br>
</div>
</td>
<td>
<div>
28 Jahre
<br>
Berlin
<br>
blond
<br>
schlank
<br>
54 kg
<br>
</div>
</td>
</tr>
</tbody>
</table>
1 2 3 4
my @keys = split /<br>/, $erstesTD; my @values = split /<br>/, $zweitesTD; my %kv; @kv{@keys} = @values;
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#!/usr/bin/perl use strict; use warnings; use 5.010; use Mojo::DOM; my $html = <<'HTML'; <table> <tbody> <tr> <td> <div> Alter: <br> Wohnort: <br> Haarfarbe: <br> Figur: <br> Gewicht: <br> </div> </td> <td> <div> 28 Jahre <br> Berlin <br> blond <br> schlank <br> 54 kg <br> </div> </td> </tr> </tbody> </table> HTML my $dom = Mojo::DOM->new($html); my ( %data_row, @keys, @val ); $dom->find('table tr td div')->each( sub { my $s = $_->content; $s =~ s/[\r\n]//g; my @data = split m|\s*<br>\s*|, $s; if ( $s =~ /:/ ) { @keys = grep /:/, @data; } else { @val = grep { !/:/ } @data; } @data_row{@keys} = (@val) if @keys; } ); say "$_ $data_row{$_}" for @keys; =comment ergibt Alter: 28 Jahre Wohnort: Berlin Haarfarbe: blond Figur: schlank Gewicht: 54 kg