begin process at 2010 03 21 10:34:27
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Réseau & Internet

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

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


 Information sur la source

Note :
6 / 10 - par 1 personne
6,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Réseau & Internet Niveau :Débutant Date de création :26/09/2004 Vu :4 898

Auteur : arnaud_tournier

Ecrire un message privé
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 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.



 Sources du même auteur

MODIFIER LA COULEUR DE FOND DU TEXTE SÉLECTIONNÉ DANS UN RIC...

 Sources de la même categorie

Source avec Zip BASE64/BASE64URL ENCODE/DECODE par f0xi
Source avec Zip AFFICHAGE DES INFODFS par fbalien
Source avec Zip Source avec une capture INTRA MESSENGER - DELPHI par keket
Source avec Zip CODAGE DÉCODAGE PDU 7BITS par AccessToYou
Source avec Zip Source avec une capture SIMPLEWEBBROWSER par cantador

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,484 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales