begin process at 2008 07 20 04:34:16
1 213 129 membres
50 nouveaux aujourd'hui
14 166 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

ENREGISTRE UN SITE WEB, LES LIENS ASSOCIÉS ET LES IMAGES CONTENUES DANS LA PAGE WEB


Information sur la source

Description

Enregistre un site WEB, les liens associés et les images contenues dans la page WEB

Source

  • unit UMain;
  • interface
  • uses
  • Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  • Dialogs, StdCtrls;
  • type
  • TForm1 = class(TForm)
  • Button1: TButton;
  • procedure Button1Click(Sender: TObject);
  • private
  • { Déclarations privées }
  • function enregistre(sHost, sBaseFichier, sURL: String) : String;
  • function RechercheEtEnregistre(sHost, sBaseFichier : String; var sTextASauver, sText : String; sDeLaBalise, sALaBalise: String): String;
  • function Parse(sHost, sBaseFichier, sText : String) : String;
  • public
  • { Déclarations publiques }
  • end;
  • var
  • Form1: TForm1;
  • implementation
  • uses idHTTP;
  • {$R *.dfm}
  • function TForm1.enregistre(sHost, sBaseFichier, sURL: String) : String;
  • var idHTTP : TIdHTTP;
  • MemoryStream : TMemoryStream;
  • sTmp : String;
  • sDir : String;
  • begin
  • idHTTP := TIdHTTP.Create(nil);
  • if sHost = '' then
  • begin
  • try
  • idHTTP.Get(sURL);
  • sHost := 'http://' + idHTTP.Host;
  • Except on exception do
  • begin
  • result := '';
  • exit;
  • end;
  • end;
  • end;
  • MemoryStream := TMemoryStream.Create;
  • if pos(sHost, sURL) > 0 then
  • begin
  • sTmp := copy(sURL,pos(sHost, sURL) + length(sHost),length(sURL));
  • end
  • else
  • begin
  • sTmp := sURL;
  • end;
  • try
  • try
  • idHTTP.Get(sHost + sTmp,MemoryStream);
  • Except on exception do
  • begin
  • Result := enregistre('', sBaseFichier, sURL);
  • exit;
  • end;
  • end;
  • sTmp := StringReplace(sTmp,'/','\',[rfReplaceAll]);
  • ForceDirectories(sBaseFichier + idHTTP.Host);
  • sTmp := StringReplace(sTmp, '|','_',[rfReplaceAll]);
  • sTmp := StringReplace(sTmp, '*','_',[rfReplaceAll]);
  • sTmp := StringReplace(sTmp, ':','_',[rfReplaceAll]);
  • sTmp := StringReplace(sTmp, '?','_',[rfReplaceAll]);
  • sTmp := sBaseFichier + idHTTP.Host + '\' + sTmp;
  • sDir := ExtractFileDir(sTmp);
  • ForceDirectories(sDir);
  • if ExtractFilename(sTmp) = '' then
  • begin
  • sTmp := sTmp + '\index.html';
  • end;
  • MemoryStream.SaveToFile(sTmp);
  • FreeAndNil(MemoryStream);
  • FreeAndNil(idHTTP);
  • result := sTmp;
  • except on e:Exception do
  • begin
  • showMessage(e.Message);
  • result := '';
  • end;
  • end;
  • end;
  • procedure TForm1.Button1Click(Sender: TObject);
  • var
  • sFilename : String;
  • slTmp : TStringList;
  • begin
  • sFilename := enregistre('http://www.delphi.fr', 'c:\', '');
  • slTmp := TStringList.Create();
  • slTmp.LoadFromFile(sFilename);
  • slTmp.Text := Parse('http://www.google.fr', 'c:\', slTmp.Text);
  • slTmp.SaveToFile(sFilename);
  • FreeAndNil(slTmp);
  • end;
  • function TForm1.RechercheEtEnregistre(sHost, sBaseFichier : String; var sTextASauver, sText : String; sDeLaBalise, sALaBalise: String): String;
  • var
  • sTmp, sOldTmp : String;
  • sFilename : String;
  • begin
  • Result := sTextASauver;
  • While pos(sDeLaBalise, sText) > 0 do
  • begin
  • sTmp := copy(sText, pos(sDeLaBalise, sText) + length(sDeLaBalise), length(sText));
  • if sTmp <> '' then
  • begin
  • sTmp := copy(sTmp,1, pos(sALaBalise, sTmp) - 1);
  • if sTmp <> '' then
  • begin
  • sFileName := enregistre(sHost, sBaseFichier, sTmp);
  • Result := StringReplace(Result,sDeLaBalise + sTmp + sALaBalise, sDeLaBalise + 'file://' + sFileName + sALaBalise,[]);
  • sText := StringReplace(sText,sDeLaBalise + sTmp + sALaBalise, '',[]);
  • end;
  • end;
  • end;
  • end;
  • function TForm1.Parse(sHost, sBaseFichier, sText: String): String;
  • begin
  • result := sText;
  • result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'src=''', '''');
  • result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'src="', '"');
  • result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'src=', '>');
  • result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'href=''', '''');
  • result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'href="', '"');
  • result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'href=', '>');
  • end;
  • end.
unit UMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Déclarations privées }
    function enregistre(sHost, sBaseFichier, sURL: String) : String;
    function RechercheEtEnregistre(sHost, sBaseFichier : String; var sTextASauver, sText : String; sDeLaBalise, sALaBalise: String): String;
    function Parse(sHost, sBaseFichier, sText : String) : String;
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

uses idHTTP;

{$R *.dfm}

function TForm1.enregistre(sHost, sBaseFichier, sURL: String) : String;
var idHTTP : TIdHTTP;
    MemoryStream : TMemoryStream;
    sTmp : String;
    sDir : String;
begin
    idHTTP := TIdHTTP.Create(nil);
    if sHost = '' then
    begin
      try
        idHTTP.Get(sURL);
        sHost := 'http://' + idHTTP.Host;
      Except on exception do
        begin
          result := '';
          exit;
        end;
      end;
    end;
    MemoryStream := TMemoryStream.Create;
    if pos(sHost, sURL) > 0 then
    begin
      sTmp := copy(sURL,pos(sHost, sURL) + length(sHost),length(sURL));
    end
    else
    begin
      sTmp := sURL;
    end;
    try
      try
        idHTTP.Get(sHost + sTmp,MemoryStream);
      Except on exception do
        begin
          Result := enregistre('', sBaseFichier, sURL);
          exit;
        end;
      end;
      sTmp := StringReplace(sTmp,'/','\',[rfReplaceAll]);
      ForceDirectories(sBaseFichier + idHTTP.Host);
      sTmp := StringReplace(sTmp, '|','_',[rfReplaceAll]);
      sTmp := StringReplace(sTmp, '*','_',[rfReplaceAll]);
      sTmp := StringReplace(sTmp, ':','_',[rfReplaceAll]);
      sTmp := StringReplace(sTmp, '?','_',[rfReplaceAll]);
      sTmp := sBaseFichier + idHTTP.Host + '\' + sTmp;
      sDir := ExtractFileDir(sTmp);
      ForceDirectories(sDir);
      if ExtractFilename(sTmp) = '' then
      begin
        sTmp := sTmp + '\index.html';
      end;
      MemoryStream.SaveToFile(sTmp);
      FreeAndNil(MemoryStream);
      FreeAndNil(idHTTP);
      result := sTmp;
    except on e:Exception do
      begin
        showMessage(e.Message);
        result := '';
      end;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
    sFilename : String;
    slTmp : TStringList;
begin
  sFilename := enregistre('http://www.delphi.fr', 'c:\', '');
  slTmp := TStringList.Create();
  slTmp.LoadFromFile(sFilename);
  slTmp.Text :=  Parse('http://www.google.fr', 'c:\', slTmp.Text);
  slTmp.SaveToFile(sFilename);
  FreeAndNil(slTmp);
end;

function TForm1.RechercheEtEnregistre(sHost, sBaseFichier : String; var sTextASauver, sText : String; sDeLaBalise, sALaBalise: String): String;
var
  sTmp, sOldTmp : String;
  sFilename : String;
begin
  Result := sTextASauver;
  While pos(sDeLaBalise, sText) > 0 do
  begin
    sTmp := copy(sText, pos(sDeLaBalise, sText) + length(sDeLaBalise), length(sText));
    if sTmp <> '' then
    begin
      sTmp := copy(sTmp,1, pos(sALaBalise, sTmp) - 1);
      if sTmp <> '' then
      begin
        sFileName := enregistre(sHost, sBaseFichier, sTmp);
        Result := StringReplace(Result,sDeLaBalise + sTmp + sALaBalise, sDeLaBalise + 'file://' + sFileName + sALaBalise,[]);
        sText := StringReplace(sText,sDeLaBalise + sTmp + sALaBalise, '',[]);
      end;
    end;
  end;
end;

function TForm1.Parse(sHost, sBaseFichier, sText: String): String;
begin
  result := sText;
  result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'src=''', '''');
  result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'src="', '"');
  result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'src=', '>');
  result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'href=''', '''');
  result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'href="', '"');
  result := RechercheEtEnregistre(sHost, sBaseFichier, result, sText, 'href=', '>');
end;

end.
    Aucun commentaire pour le moment.

Ajouter un commentaire

Pub



Appels d'offres

Dessins techniques
Budget : 60€
Animation Flash - Doma...
Budget : 370€
Application flash medi...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Boutique

Boutique de goodies CodeS-SourceS