Accueil > > > 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
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
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
L'INTERFACE NATURELLE DE WINDOWS PHONE 7 SERIESL'INTERFACE NATURELLE DE WINDOWS PHONE 7 SERIES par odewit
La tendance est aux interfaces naturelles (NUI), et le keynote de Bill Buxton au MIX l'a bien souligné.
La charte graphique et ergonomique de Windows Phone 7 a donc été entièrement repensée en vue d'obtenir un maximum d'efficacité sur ce point. En re...
Cliquez pour lire la suite de l'article par odewit COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE?COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE? par Matthieu MEZIL
Avec EF, les vues doivent être mappées sur des entity types. Le problème c'est que les entity types doivent avoir une clé. Avec EF, nous avons les complex type qui n'ont pas de clé mais les vues ne peuvent pas être mappées dessus. Avec EF4, il est possibl...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL?[WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL? par JeremyJeanson
Certain d'entre vous on peut être vécu cette situation embarrassante après quelques temps passer avec WF4 : Au début avec mon " ActivityDesigner" , tout allait bien. Et puis un jour j'ai au des problèmes de " Binding" . Alors nous sommes allé sur le site ...
Cliquez pour lire la suite de l'article par JeremyJeanson
Forum
QREPORT QREPORT par lounnaci
Cliquez pour lire la suite par lounnaci [à SUPPRIMER][à SUPPRIMER] par br1969
Cliquez pour lire la suite par br1969
Logiciels
Academy System (10.9.4.0)ACADEMY SYSTEM (10.9.4.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods
|