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:= '';
Str:= Bajar(Url);
i:= Pos(Uppercase(Etiqueta), Uppercase(Str));
if i > 0 then
begin
while (Copy(Str,i,1)<>'>') and (i<Length(Str)) do
inc(i);
inc(i);
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.