Ver Mensaje Individual
  #4  
Antiguo 17-08-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Seguro que usando un TWebbrowser se pueden ir recorriendo cada una de las etiquetas (aunque yo no se como ), o quizá utilizando algún parser. Pero una forma sencilla de hacerlo es obtener la pagina, colocarla en un string, buscar la etiqueta textarea y copiar lo que se encuentra entre la etiqueta de apertura y de cierre. Algo así:

Código Delphi [-]
program gettext;

{$APPTYPE CONSOLE}

uses
  Windows, SysUtils, WinInet;


function Bajar(Url: string): String;
var
  hNet: HINTERNET;
  hUrl: HINTERNET;
  Buffer: array[0..10240] of Char;
  BytesRead: Cardinal;
begin
  Result := '';
  hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if (hNet <> nil) then
  begin
    hUrl := InternetOpenUrl(hNet, PChar(Url), nil, 0,
      INTERNET_FLAG_RELOAD, 0);
    if (hUrl <> nil) then
    begin
      FillChar(Buffer,Sizeof(Buffer),0);
      while (InternetReadFile(hUrl, @Buffer, sizeof(Buffer), BytesRead)) do
      begin
        if (BytesRead = 0) then
          break;
        Result:= Result + String(PChar(@Buffer));
        FillChar(Buffer,Sizeof(Buffer),0);
      end;
      InternetCloseHandle(hUrl);
    end;
    InternetCloseHandle(hNet);
  end;
end;

function ObtenerTexto(Url: string; Etiqueta: string): string;
var
  Str: string;
  i: integer;
begin
  Result:= '';
  // Bajamos la pagina
  Str:= Bajar(Url);
  // Buscamos la etiqueta
  i:= Pos(Uppercase(Etiqueta), Uppercase(Str));
  if i > 0 then
  begin
    // Buscamos el final de la etiqueta
   while (Copy(Str,i,1)<>'>') and (i<Length(Str)) do
      inc(i);
   inc(i);
   // Copiamos el texto hasta encontrar otra etiqueta
   while (Copy(Str,i,1)<>'<') and (i<Length(Str)) do
   begin
      Result:= Result + Copy(Str,i,1);
      inc(i);
   end;
  end;
end;

begin
  Writeln(ObtenerTexto('http://www.mipagina.com/index.html','<textarea'));
  readln;
end.

Última edición por seoane fecha: 17-08-2006 a las 14:58:35.
Responder Con Cita