Используете TidHttp для загрузки изображений Jpeg с URL (только тех, которые существуют)?

Я пытаюсь извлечь большое количество изображений из Интернета с помощью компонента TidHttp.

Проблема в том, что отсутствует ряд изображений (пример: 7403, 7412 и т.д.)

Как проверить только те, которые существуют, и сохранить их в файл?

procedure TForm.Button1Click(Sender: TObject);
var
  MS : TMemoryStream;
  JPEGImage: TJPEGImage;
  Url, numString: String;
  I, Code: Integer;
begin
 for I := 7400 to 7500 do
 begin
 { 
   Url        :='http://www.mywebpage.com/images/DSC' + numString+  '.jpg';
   try
   idhttp1.Head(URL);
   code := idhttp1.ResponseCode;
   except on E: EIdHTTPProtocolException do
    code := idhttp1.ResponseCode;
   end;//try except
   if code = 200 then
   begin

   MS := TMemoryStream.Create;
   JPEGImage  := TJPEGImage.Create;
   try
     try
     idhttp1.Get(Url, MS); //Send the request and get the image
     code := idhttp1.ResponseCode;
     MS.Seek(0,soFromBeginning);
     JPEGImage.LoadFromStream(MS);//load the image in a Stream
     Image1.Picture.Assign(JPEGImage);//Load the image in a Timage component
     Image1.Picture.SaveToFile('C:\Museum_Data\DSC' + numString + '.jpg');
     Application.ProcessMessages;
     except
      on E: EIdHTTPProtocolException do
        code := idhttp1.ResponseCode; // or: code := E.ErrorCode;
     end; //try except
          finally
    MS.free;
    JPEGImage.Free;

  end; //try finally
  end; //if

end;
 end;
6
задан Shane 1 December 2011 в 01:00
поделиться