Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi Ausgabe (ohne HTML Tags) mit IdHTTP?! (https://www.delphipraxis.net/25077-ausgabe-ohne-html-tags-mit-idhttp.html)

Plague 30. Jun 2004 21:53


Ausgabe (ohne HTML Tags) mit IdHTTP?!
 
Hallo,

ich habe eben in einem kleinen Programm eine Abfrage von einer PHP Seite programmiert. Die Ausgabe erfolgt aber leider im HTML Quelltext. Kann ich irgendwie einstellen, dass ich nur den Text ausgegeben bekomme, der beispielsweise auch im Browser zu sehen ist?

Danke im Vorraus!
Gruß
Thomas

sakura 30. Jun 2004 21:56

Re: Ausgabe (ohne HTML Tags) mit IdHTTP?!
 
Nein, IdHttp - wie auch alle anderen Komponenten dieser Art - liefert Dir den genauen Bytestream zurück, welchen es vom Server erhält. An dieser Stelle musst Du selbst parsen, bzw. bei www.torry.net mal nach HTML Parsern suchen.

...:cat:...

StefanDP 30. Jun 2004 22:25

Re: Ausgabe (ohne HTML Tags) mit IdHTTP?!
 
hab da mal was programmiert: (ist ziemlich überladen, kann man vielleicht irgendwie kürzen...)
Delphi-Quellcode:
function TAuswerten.PlainText(strHTML: string): string;
var
  P: PChar;
  InTag: Boolean;
begin
  // <head> löschen
  while (Pos('<head',strHTML) > 0) and
        (Pos('</head>',strHTML) > Pos('<head',strHTML)) do
    Delete(strHTML, Pos('<head',strHTML), (Pos('</head>',strHTML) + 7) - Pos('<head',strHTML));
  // <script> löschen
  while (Pos('<script',strHTML) > 0) and
        (Pos('</script>',strHTML) > Pos('<script',strHTML)) do
    Delete(strHTML, Pos('<script',strHTML), (Pos('</script>',strHTML) + 9) - Pos('<script',strHTML));
  // <style> löschen
  while (Pos('<style',strHTML) > 0) and
        (Pos('</style>',strHTML) > Pos('<style',strHTML)) do
    Delete(strHTML, Pos('<style',strHTML), (Pos('</style>',strHTML) + 8) - Pos('<style',strHTML));

  // Alle tags werden durch leerzeichen ersetzt
  strHTML := StringReplace(strHTML,'>','> ',[rfReplaceAll]);
  P := PChar(strHTML);
  Result := '';

  InTag := False;
  repeat
    case P^ of
      '<': InTag := True;
      '>': InTag := False;
      #13, #10: ; // nichts machen
      else
        if not InTag then
        begin
          if (P^ in [#9, #32]) and ((P+1)^ in [#10, #13, #32, #9, '<']) then
          else
            Result := Result + P^;
        end;
    end;
    Inc(P);
  until (P^ = #0);

  Result := StringReplace(Result, '&auml;', 'ä', [rfReplaceAll]);
  Result := StringReplace(Result, '&ouml;', 'ö', [rfReplaceAll]);
  Result := StringReplace(Result, '&uuml;', 'ü', [rfReplaceAll]);
  Result := StringReplace(Result, '&szlig;', 'ß', [rfReplaceAll]);
  Result := StringReplace(Result, '', ' ', [rfReplaceAll]);
  Result := StringReplace(Result, '*', ' ', [rfReplaceAll]);
  Result := StringReplace(Result, '&gt;', '>', [rfReplaceAll]);
  Result := StringReplace(Result, '&lt;', '<', [rfReplaceAll]);
{  Result := StringReplace(Result, '&quot;', '"', [rfReplaceAll]);
  Result := StringReplace(Result, '&apos;', '''', [rfReplaceAll]);
  Result := StringReplace(Result, '&amp;', '&', [rfReplaceAll]);}
end;
stefan

Meflin 1. Jul 2004 13:43

Re: Ausgabe (ohne HTML Tags) mit IdHTTP?!
 
oder siehe auch dieser thread:
http://www.delphipraxis.net/internal...ct.php?t=28837


Alle Zeitangaben in WEZ +1. Es ist jetzt 16:17 Uhr.

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