Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]3024[/thread]

Daten extrahieren

Leser: 1


<< >> 3 Einträge, 1 Seite
elvira
 2006-06-17 14:08
#28575 #28575
User since
2006-06-14
5 Artikel
BenutzerIn
[default_avatar]
Hallo!

Wie kann ich die Daten wie z.B. Bug ID, Category, Severity...aus der folgenden HTML Datei extrahieren?

Code: (dl )
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
<tr class="row-1">

<!-- Bug ID -->

<td>
0007044 </td>

<!-- Category -->
<td>
[mantisbt] custom fields </td>

<!-- Severity -->
<td>

minor </td>

<!-- Reproducibility -->
<td>
always </td>

<!-- Date Submitted -->
<td>
05-08-06 00:26 </td>

<!-- Date Updated -->
<td>
05-08-06 00:26 </td>

</tr>


ich habe's mit
Code: (dl )
if($row=~/<tr class="row-1">(.+)<\/tr>/m)

versucht, aber geht nicht...

bitte um Hilfe :)

code-tags von betterworld\n\n

<!--EDIT|betterworld|1150539201-->
betterworld
 2006-06-17 14:16
#28576 #28576
User since
2003-08-21
2613 Artikel
ModeratorIn

user image
Du könntest ein Modul wie CPAN:HTML::Parser benutzen.
topeg
 2006-07-17 18:52
#28577 #28577
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
HTML::Parser wäre auch meine erste Wahl, doch nicht immer steht er zur Verfügung.
Wenn die Kommentare "<!-- -->" immer drin sind, dann könntest du die hinzu ziehen. Ich gehe mal davon aus, daß es mehrere "<tr>...</tr>" Blöcke gibt.
Mal als Vorschlag:
Code: (dl )
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
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

# hier soll die Seite drin sein:
my $html=<<TPG;
<tr class="row-1">

<!-- Bug ID -->

<td>
0007044 </td>

<!-- Category -->
<td>
[mantisbt] custom fields </td>

<!-- Severity -->
<td>

minor </td>

<!-- Reproducibility -->
<td>
always </td>

<!-- Date Submitted -->
<td>
05-08-06 00:26 </td>

<!-- Date Updated -->
<td>
05-08-06 00:26 </td>

</tr>
<tr class="row-1">

<!-- Bug ID -->

<td>
0007046 </td>

<!-- Category -->
<td>
[mantisbt] custom fields </td>

<!-- Severity -->
<td>

minor </td>

<!-- Reproducibility -->
<td>
never </td>

<!-- Date Submitted -->
<td>
05-08-06 10:26 </td>

<!-- Date Updated -->
<td>
05-08-06 10:26 </td>

</tr>
<tr class="row-1">
<td>was ganz anderes</td>
</tr>
TPG
my @data=();
# als erstes den "<tr>..</tr>" Block extrahieren:
while($html=~m|<tr[^>]+>(.+?)</tr>|is)
{
# hier kommt alles rein,
# was in einem Block steht
my $inhalt=$1;
# nur das Ungeparste behalten.
$html=$';
# hier kommen die gesuchten Daten rein
my %datensatz=();
# Datensätze herausfischen
while($inhalt=~m|<!--\s+(.+?)\s+-->\s+<td>\s+(.+?)\s+</td>|is)
{
$inhalt=$';
$datensatz{lc($1)}=$2;
}
push(@data,\%datensatz)if(%datensatz>0);
}
print Dumper(\@data);
\n\n

<!--EDIT|topeg|1153148070-->
<< >> 3 Einträge, 1 Seite



View all threads created 2006-06-17 14:08.