Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Parsen von htm Datei und Informationen trennen mit Semikolon (https://www.delphipraxis.net/119019-parsen-von-htm-datei-und-informationen-trennen-mit-semikolon.html)

Mackhack 19. Aug 2008 18:06


Parsen von htm Datei und Informationen trennen mit Semikolon
 
Hallo DPler,

ich habe eine htm Datei die folgendermassen aufgebaut ist:

Zitat:

<HTML><HEAD><TITLE>Application Verifier Results for TEST-PC</TITLE></HEAD>
<BODY bgcolor=#FFF8DC><H1>Application Verifier Results for TEST-PC</H1>
<TABLE BORDER CELLPADDING=2 bgcolor='white'>
<TR bgcolor='black'><TH WIDTH=75 ALIGN=CENTER NOWRAP><FONT COLOR='white'>Status</TH><TH NOWRAP><FONT COLOR='white'>Application</TH><TH NOWRAP><FONT COLOR='white'>Layer Name</TH><TH NOWRAP><FONT COLOR='white'>Failure</TH><TH NOWRAP><FONT COLOR='white'>Stop Code</TH><TH NOWRAP><FONT COLOR='white'>Parameter 1</TH><TH NOWRAP><FONT COLOR='white'>Parameter 2</TH><TH NOWRAP><FONT COLOR='white'>Parameter 3</TH><TH NOWRAP><FONT COLOR='white'>Parameter 4</TH><TH NOWRAP><FONT COLOR='white'>Probable Cause</TH><TH NOWRAP><FONT COLOR='white'>Additional Information</TH></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>Acrobat.com.exe</TD> <TD>COM</TD> <TD>COM API or Proxy called from DllMain.</TD> <TD>0x401</TD> <TD>0 - Not used.</TD> <TD>0 - Not used.</TD> <TD>0 - Not used.</TD> <TD>0 - Not used.</TD> <TD>This stop is generated when a COM Proxy or a dangerous COM API is called with the loader lock held</TD> <TD>To debug this run a simple kb' to get the stack of the misbehaving DLL. The DLL should remove its call to the COM API in question.</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>Acrobat.com.exe</TD> <TD>Locks</TD> <TD>Unloading DLL containing an active critical section.</TD> <TD>0x201</TD> <TD>1077a108 - Critical section address.</TD> <TD>42b990 - Critical section initialization stack trace.</TD> <TD>26fefe2 - DLL name address.</TD> <TD>10000000 - DLL base address.</TD> <TD>This stop is generated if a DLL has a global variable containing a critical section and the DLL is unloaded but the critical section has not been deleted.</TD> <TD>Check the contents of the current call stack when the DLL with the active lock was unloaded. Frequency of this error is high. To debug this stop use the following debugger commands:

du parameter3 to dump the name of the culprit DLL.

.reload dllname or .reload dllname = parameter4 - to reload the symbols for that DLL.

!css parameter1 - dump information about this critical section.

ln parameter1 to show symbols near the address of the critical section. This should help identify the leaked critical section.

dds parameter2 to dump the stack trace for this critical section initialization.</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>AOLDesktop.exe</TD> <TD>Memory</TD> <TD>Probing free memory.</TD> <TD>0x604</TD> <TD>733effff - Start address.</TD> <TD>8 - Memory block size.</TD> <TD>733ef000 - Address of free memory page.</TD> <TD>0 - Not used.</TD> <TD>&nbsp</TD> <TD>&nbsp</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>AOLDesktop.exe</TD> <TD>TLS</TD> <TD>Unloading DLL that allocated TLS index that was not freed.</TD> <TD>0x350</TD> <TD>21abba - TLS index</TD> <TD>6c009aed - Address of the code that allocated this TLS index.</TD> <TD>261cfe0 - DLL name address. Use du to dump it.</TD> <TD>6c000000 - DLL base address.</TD> <TD>&nbsp</TD> <TD>&nbsp</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>AOLDesktop.exe</TD> <TD>Memory</TD> <TD>Probing free memory.</TD> <TD>0x604</TD> <TD>7c35f07d - Start address.</TD> <TD>1 - Memory block size.</TD> <TD>7c35f000 - Address of free memory page.</TD> <TD>0 - Not used.</TD> <TD>&nbsp</TD> <TD>&nbsp</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#90EE90>Passed</TD><TD COLSPAN=10>aollaunch.exe</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#90EE90>Passed</TD><TD COLSPAN=10>aolload.exe</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>AolTbServer.exe</TD> <TD>Heaps</TD> <TD>First chance access violation for current stack trace.</TD> <TD>0x13</TD> <TD>54def94 - Invalid address causing the exception.</TD> <TD>7675f3e7 - Code address executing the invalid access.</TD> <TD>12f1cc - Exception record.</TD> <TD>12f1e8 - Context record.</TD> <TD>This is the most common application verifier stop. Typically it is caused by a buffer overrun error. The heap verifier places a non-accessible page at the end of a heap allocation and a buffer overrun will cause an exception by touching this page. There are several other causes for this stop. For example, accessing a heap block after being freed. The same debugger command will be useful for this case too.</TD> <TD>To debug this stop identify the access address that caused the exception and then use the following debugger command: !heap -p -a ACCESS_ADDRESS
This command will give details about the nature of the error and what heap block is overrun. It will also give the stack trace for the block allocation.</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>AolTbServer.exe</TD> <TD>COM</TD> <TD>Unhandled exception in COM call.</TD> <TD>0x402</TD> <TD>12ea24 - Exception pointers for exception.</TD> <TD>412ff0 - Object being called on.</TD> <TD>7617f08 - Pointer to IID being called on.</TD> <TD>b - Method number being called on.</TD> <TD>&nbsp</TD> <TD>&nbsp</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>AolTbServer.exe</TD> <TD>COM</TD> <TD>Unhandled exception in COM call.</TD> <TD>0x402</TD> <TD>12e354 - Exception pointers for exception.</TD> <TD>412ff0 - Object being called on.</TD> <TD>7617f08 - Pointer to IID being called on.</TD> <TD>b - Method number being called on.</TD> <TD>&nbsp</TD> <TD>&nbsp</TD></TR>
<TR><TD WIDTH=75 ALIGN=CENTER bgcolor=#FFB6C1>Failed</TD><TD>AolTbServer.exe</TD> <TD>COM</TD> <TD>Unhandled exception in COM call.</TD> <TD>0x402</TD> <TD>12dc84 - Exception pointers for exception.</TD> <TD>412ff0 - Object being called on.</TD> <TD>7617f08 - Pointer to IID being called on.</TD> <TD>b - Method number being called on.</TD> <TD>&nbsp</TD> <TD>&nbsp</TD></TR>
Das ist jetzt nur mal der obere Teil. Die File hat immer ca. 600 solcher Eintraege. Die Informationen sehen in einem Editor eleganer und leserlich aus nur hier jetzt mit Zeilenumbruch nicht.

Meine Frage nun ist wie bekomme ich die Informationen zwischen diesen <TD> Tags ausgelesen und mit einem ";" separiert? Dachte schon an Pos(Ex) zum suchen der Tags.

Gibts elegantere Loesungen? Ausserdem sollen nur die die "Failed" haben ausgelesen werden. Die anderen koennen ignoriert werden!

Danke!

omata 19. Aug 2008 18:07

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
Zitat:

Zitat von Mackhack
Gibts elegantere Loesungen?

Ja, Reguläre Ausdrücke.

Mackhack 19. Aug 2008 18:08

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
Zitat:

Zitat von omata
Zitat:

Zitat von Mackhack
Gibts elegantere Loesungen?

Ja, Reguläre Ausdrücke.

Wie meinen?

mkinzler 19. Aug 2008 18:11

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
http://de.wikipedia.org/wiki/Regul%C...Ausdr%C3%BCcke
http://regexpstudio.com/TRegExpr/TRegExpr.html

shmia 19. Aug 2008 18:14

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
Am Besten verwendet man einen HTML-Parser.
HTML Tabelle einlesen
Man kann auch mit regulären Ausdrücken da rangehen, aber mit dem HTML-Parser ist man besser bedient.

Mackhack 19. Aug 2008 18:15

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
Hallo mkienzler,

ist das nicht das was ich fragte mit den Tags? Dass ich danach suchen muss und dann ab dem Tag anfange zu kopieren? Wenn ja wie mach ich dann weiter nachdem ich die erste Information habe?

//Mal diesen HTML Parser ansehen

marabu 19. Aug 2008 18:23

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
Hallo Tobias,

vielleicht erkennst du gewisse Parallelen zu deinem Problem: HTML Tabelle einlesen

Die Ausgabe als CSV-Datei könntest du leicht mittels DelimitedText erledigen.

Freundliche Grüße

Mackhack 19. Aug 2008 18:30

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
Zitat:

Zitat von marabu
Hallo Tobias,

vielleicht erkennst du gewisse Parallelen zu deinem Problem: HTML Tabelle einlesen

Die Ausgabe als CSV-Datei könntest du leicht mittels DelimitedText erledigen.

Freundliche Grüße

Genau so wollte ich das machen. Nur hab ich wie der Threadersteller von deinem Link auch noch nie was damit zuvor gemacht und muss mir das erstmal ansehen. Aber vielen Dank fuer deinen Post!

omata 19. Aug 2008 18:32

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
Delphi-Quellcode:
procedure HTMLtoCSV(HTML:string; CSV:TStrings);
var RegExpr_TR, RegExpr_TD:TRegExpr;
    s:string;
begin
  RegExpr_TR:=TRegExpr.Create;
  RegExpr_TD:=TRegExpr.Create;
  try
    RegExpr_TR.ModifierG:=false;
    RegExpr_TR.ModifierI:=true;
    RegExpr_TR.Expression :='<tr><td.*?>failed(.*)</tr>';

    RegExpr_TD.ModifierG:=false;
    RegExpr_TD.ModifierI:=true;
    RegExpr_TD.Expression :='<td.*?>(.*)</td>';

    s:=StringReplace(HTML, #13, '', [rfReplaceAll]);
    s:=StringReplace(s, #10, '', [rfReplaceAll]);
    if RegExpr_TR.Exec(s) then begin
      repeat
        if RegExpr_TD.Exec(RegExpr_TR.Match[1]) then begin
          s:='';
          repeat
            s:=s + RegExpr_TD.Match[1] + ';';
          until not RegExpr_TD.ExecNext;
          CSV.Append(s);
        end;
      until not RegExpr_TR.ExecNext;
    end;
  finally
    RegExpr_TR.free;
    RegExpr_TD.free;
  end;
end;
RegExpr

grenzgaenger 19. Aug 2008 20:38

Re: Parsen von htm Datei und Informationen trennen mit Semik
 
guck mal in die open source libary, da hat alzheimer mal was eingestellt, was mit grösseren trennzeichen umgehen kann...

damit sollt es ein leichtes sein, deinen string zu zerlegen.


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:05 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz