Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi "Wer ist Online"-Box auslesen ohne Indy (https://www.delphipraxis.net/72072-wer-ist-online-box-auslesen-ohne-indy.html)

turboPASCAL 25. Jun 2006 10:42


"Wer ist Online"-Box auslesen ohne Indy
 
Hi,

ich mochte gern die "Wer ist Online"-Box ohne Indy auslesen und nach den registrierten Benutzern parsen.

Wie kann ich mir die Seite ohne Indy in einen Memorystream downloaden ?

Balu der Bär 25. Jun 2006 10:45

Re: "Wer ist Online"-Box auslesen ohne Indy
 
Du könntest die Seite auch in nen TWebBrowser laden, im Quelltext dann nach der entsprechenden Stelle suchen und alle Links auslesen.

turboPASCAL 25. Jun 2006 10:49

Re: "Wer ist Online"-Box auslesen ohne Indy
 
TWebBrowser, ja ist eine Idee, allerdings die letzte Möglichkeit/Option die ich machen möchte.
Lieber wäre mir mit API-Funktionen.

Die Muhkuh 25. Jun 2006 10:49

Re: "Wer ist Online"-Box auslesen ohne Indy
 
Ich seh es kommen, der DP braucht eine Api (DP-Api) :mrgreen:

alcaeus 25. Jun 2006 10:50

Re: "Wer ist Online"-Box auslesen ohne Indy
 
http://www.delphipraxis.net/internal_redirect.php?t=75 ;)
Anschliessend eben die Temp-Datei in einen Stream laden und gut is

Greetz
alcaeus

SirThornberry 25. Jun 2006 10:51

Re: "Wer ist Online"-Box auslesen ohne Indy
 
schau dir mal die Funktionen aus der unit "wininet" an welche mit "http" beginnen. Vielleicht ist da was dabei.

Gerome 25. Jun 2006 10:52

Re: "Wer ist Online"-Box auslesen ohne Indy
 
Zitat:

Zitat von Spider
Ich seh es kommen, der DP braucht eine Api (DP-Api) :mrgreen:

Gibt es bereits, wird aber erst für die DP2006 vervollständigt und veröffentlicht. Im ersten Schritt ist das API-System dann readonly (mit eigenem Cache).


Grüße,
Gérome

Die Muhkuh 25. Jun 2006 10:53

Re: "Wer ist Online"-Box auslesen ohne Indy
 
Zitat:

Zitat von Gérome
Zitat:

Zitat von Spider
Ich seh es kommen, der DP braucht eine Api (DP-Api) :mrgreen:

Gibt es bereits, wird aber erst für die DP2006 vervollständigt und veröffentlicht. Im ersten Schritt ist das API-System dann readonly (mit eigenem Cache).


Grüße,
Gérome

:thumb: Nice!

turboPASCAL 25. Jun 2006 11:51

Re: "Wer ist Online"-Box auslesen ohne Indy
 
So, ich habs nun erst mal in der Form:

Delphi-Quellcode:
uses
  wininet;

function _PosEx(const Substr: string; const S: string; Offset: Integer): Integer;
begin
  if Offset <= 0 then Result := 0 else
    Result := Pos(Substr, Copy(S, Offset, Length(S)));

  if Result <> 0 then
    Result := Result + Offset - 1;
end;

function CopyFileFromURL(const URL: String; MS: TMemoryStream): Boolean;
const
  BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[0..BufferSize-1] of Char;
  BufferLength: DWORD;
begin
  Result := False;
  hSession := InternetOpen(PChar(Application.Title),
                INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  try
    hURL := InternetOpenURL(hSession, PChar(URL), nil, 0, 0, 0);
    try
      MS.Position := 0;
      repeat
        InternetReadFile(hURL, @Buffer, BufferSize, BufferLength);
        MS.WriteBuffer(Buffer, BufferLength);
      until BufferLength = 0;
      Result := True;
    finally
      InternetCloseHandle(hURL);
    end;
  finally
    InternetCloseHandle(hSession);
  end;
end;

function IsOnline: Boolean;
var dlvFlag : DWord;
begin
  Result := FALSE;
  dlvFlag := Internet_Connection_Modem + Internet_Connection_Lan + Internet_Connection_Proxy;
  if InternetGetConnectedState ( @dlvFlag, 0 ) = TRUE Then
    Result := dlvFlag = 81;
end;

function GetDPOnlineUsers: String;
const
  strDP_URL = 'http://www.delphipraxis.net/index.html';
var
  ms: tmemorystream;
  buf: array [0..pred(1024)] of Char;
  count: Int64;
  FoundAt, i, n: Integer;
  s: String;
begin
  Result := '';

  if not IsOnline then
  begin
    Result := 'n/a';
    exit;
  end;

  ZeroMemory(@Buf, sizeof(Buf));
  ms := tmemorystream.Create;
  try
    if CopyFileFromURL(strDP_URL, ms) then
    begin
      if ms.Size >= length(buf) then
      begin
        count := 0;
        repeat
         ms.Position := count;
         ms.ReadBuffer(buf, sizeof(Buf));

         // Find Users in HTML

         FoundAt := Pos('Registrierte Benutzer:', String(buf));
         if FoundAt <> 0 then
         begin
           count := count + FoundAt;
           break;
         end;
         inc(count);
        until count+sizeof(buf) >= ms.Size ;

        if FoundAt <> 0 then
        begin
          ZeroMemory(@Buf, sizeof(Buf));
          s := '';
          while not (Pos('</span>', s) <> 0) do
          begin
            ms.ReadBuffer(buf, sizeof(Buf));
            s := s + String(buf);
          end;
        end;
      end;
    end else
      MessageBox(Application.Handle, 'Error', 'Information', MB_OK);
  finally
    ms.Free;
  end;

  if length(s) > 0 then // Parse HTML
  begin
    s := Copy(s, 1, Pos('</span>', s)-1);
    for i := 1 to length(s) do
      if s[i] < #32 then delete(s,i,1);
      i := 1;
    repeat
      i := _PosEx('<', s, i);
      n := _PosEx('>', s, i);
      delete(s, i, n-i+1);
    until not (i <> 0);
    Result := Trim(s);
  end;
end;

turboPASCAL 25. Jun 2006 14:49

Re: "Wer ist Online"-Box auslesen ohne Indy
 
So, ok, fertig, done. ;)

Ich hoffe mal das die beiden DP-Code-Maker es erst mal den HTML-Code so belassen,
sonst macht das "parsen" nicht mehr mit. ;)

Ist nicht Perfeckt aber funktioniert bestens. Danke für die Hilfe.


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:49 Uhr.

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