Hola
El proceso es el siguiente:
- descargar el contenido HTML de la página
- Analizar el contenido HTML en busca del patrón que contenga los ficheros que deseas
- Descargar el fichero desde la URL obtenida anteriormente.
Aquí te dejo un código de ejemplo, para que funcione inserta un componente TIdHTTP de las indy en tu formulario
Código Delphi
[-]
procedure TForm2.Button1Click(Sender: TObject);
function GetHTMLContent(const AURL: string): string;
begin
Result := '';
if AURL <> '' then
try
try
Result := IdHTTP1.Get(AURL);
finally
if (IdHTTP1.ResponseCode <> 200) then begin
Result := '';
MessageDlg(IdHTTP1.ResponseText, mtError, [mbOK], 0);
end;
end;
except
on E: Exception do
MessageDlg(E.message, mtError, [mbOK], 0);
end;
end;
function GetURLZip(const AContent: string; const Prefijo: string = '''../zips/cheques/'; const Sufijo: string = '.zip'''): string;
var
inicio, fin, longitud:Integer;
begin
Result := '';
inicio := Pos(Prefijo, AContent);
if inicio > 0 then begin
fin := Pos(Sufijo, AContent, inicio);
if (fin > inicio) then begin
longitud := (fin + Sufijo.Length) - inicio;
Result := Copy(AContent, inicio, longitud);
Result := result.Replace('''', '').Replace('../', '');
end;
end;
end;
function ExtractFileNameFromURL(const AURL: string): string;
Begin
with TStringList.Create do
try
StrictDelimiter := true;
Delimiter := '/';
DelimitedText := AURL;
Result := Strings[count - 1];
finally
Free;
end;
End;
function DescargarFileURL(const AURL: string): string;
var
s: TStream;
LocalFileName:string;
begin
Result := '';
try
LocalFileName := ExtractFilePath(Application.ExeName) + ExtractFileNameFromURL(AURL);
s := TFileStream.Create(LocalFileName, fmCreate);
try
IdHttp1.Get(AURL, s);
if IdHTTP1.ResponseCode = 200 then
result := LocalFileName
else
MessageDlg(IdHTTP1.ResponseText, mtError, [mbOK], 0);
finally
s.Free;
end;
except
on E: Exception do
MessageDlg(E.message, mtWarning, [mbOK], 0);
end;
end;
function DonwloadZIP (const APageBase, AURL:string):string;
var
HTMLContent, URLZip: string; LocalFileZip: string; begin
HTMLContent := GetHTMLContent(APageBase + AURL);
if (HTMLContent = '') then
MessageDlg('No se ha podido realizar la descarga', mtError, [mbOK], 0)
else begin
URLZip := GetURLZip(HTMLContent);
if URLZip = '' then
MessageDlg('No se ha podido extraer la URL del fichero ZIP', mtError, [mbOK], 0)
else begin
LocalFileZip := DescargarFileURL(APageBase + URLZip);
if LocalFileZip = '' then
MessageDlg('No se ha podido descargar el fichero ZIP desde la URL ', mtError, [mbOK], 0)
else
result := LocalFileZip;
end;
end;
end;
var
FileName: string;
begin
FileName := DonwloadZIP('http://www.bcra.gob.ar/', 'cheques/actualiza.asp');
if FileName <> '' then
MessageDlg('Descarga completa', mtInformation, [mbOK], 0)
else
MessageDlg('Error en la descarga', mtError, [mbOK], 0);
end;
Añadir que como peculiaridad, para realizar las llamadas he separado la URL en dos partes, <ruta publica del servidor> y ruta al script que se va a ejecutar. Con esto se facilita el poder obtener luego la ruta al ZIP, puesto que la URL del zip contiene "../" que es un retroceso en la carpeta de la ruta con respecto a la ruta que hay en el momento.
saludos