Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 21:31

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Delphi HTML Datei herunterladen

Discussion on Delphi HTML Datei herunterladen within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
SwagBack's Avatar
 
elite*gold: 0
Join Date: Jan 2012
Posts: 355
Received Thanks: 42
Delphi HTML Datei herunterladen

Jo Leute !

Ich bin noch ein noob in Delphi und wollte fragen ob man sich irgendwie eine HTML Datei (inklusive Bilder) aus dem Netz saugen kann (z.B. Ein Online Magazin)

Als anfänger habe ich noch nicht soviel erfahrung also währen tutorials am besten

(Die html datei soll nach einem Buttoklick heruntergeladen werden und eine variable für den namen die url und das Archiv hab ich schon)

Gruß Sw$G
SwagBack is offline  
Old 04/02/2015, 23:51   #2
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,137
Received Thanks: 572
Naja so einfach wird das nicht, du musst zunächst mal den HTML Text runterladen, dafür eignet sich am besten mit der TIdHttp Klasse.

Danach musst du die HTML Datei parsen und alle Bild URLs kopieren runterladen (wieder tidhttp), und dann die lokalen Pfade ersetzen.
warfley is offline  
Old 04/03/2015, 15:17   #3
 
SwagBack's Avatar
 
elite*gold: 0
Join Date: Jan 2012
Posts: 355
Received Thanks: 42
Quote:
Originally Posted by warfley View Post
Naja so einfach wird das nicht, du musst zunächst mal den HTML Text runterladen, dafür eignet sich am besten mit der TIdHttp Klasse.

Danach musst du die HTML Datei parsen und alle Bild URLs kopieren runterladen (wieder tidhttp), und dann die lokalen Pfade ersetzen.
Hab das jetzt mir INDY Komponente geschafft jedoch komme ich beim parsen nicht weiter haste ein tut oder code beispiel für mich ?

Gruß
SwagBack is offline  
Old 04/03/2015, 18:46   #4
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,137
Received Thanks: 572
hier ist mal ein kleines Beispiel:
Code:
procedure TForm1.Button1Click(Sender: TObject);

  procedure CheckCSS(CSS: string; lst: TStringList);
  begin
    //Parse CSS here
  end;

  procedure CheckForLocalFiles(tag: PHtmlTag; lst: TStringList);
  var
    i: integer;
  begin
    if Assigned(lst) then
    begin
      if tag^.TagType = 'style' then
        CheckCSS(tag^.Content, lst)
      else if tag^.TagType = 'link' then
      begin
        for i := 0 to tag^.Propertys.Count - 1 do
        begin
          if PTagProperty(tag^.Propertys[i])^.Name = 'href' then
            if AnsiEndsText('.css', PTagProperty(tag^.Propertys[i])^.Value) then
            begin
              lst.Add(PTagProperty(tag^.Propertys[i])^.Value);
            end;
        end;
      end
      else
      begin
        for i := 0 to tag^.Propertys.Count - 1 do
        begin
          if PTagProperty(tag^.Propertys[i])^.Name = 'style' then
            CheckCSS(PTagProperty(tag^.Propertys[i])^.Value, lst)
          else if PTagProperty(tag^.Propertys[i])^.Name = 'src' then
            lst.Add(PTagProperty(tag^.Propertys[i])^.Value);
        end;
      end;
      for i := 0 to tag^.SubTags.Count - 1 do
        CheckForLocalFiles(PHtmlTag(tag^.SubTags[i]), lst);
    end;
  end;

var
  DL_Links: TStringList;
  Htm: THtmlFile;
  htmText: string;
  i: integer;
begin
  DL_Links := TStringList.Create;
  try
    htmText := IdHTTP1.Get('Link');
    Htm := THtmlFile.Create;
    try
      Htm.LoadHtmlFromString(htmText);
      CheckForLocalFiles(Htm.Tags, DL_Links);
      // Hier Dateien runterladen und ggf seperat parsen (css dateien)

      for i:=0 to DL_Links.Count-1 do
      begin
        htmText:=StringReplace(htmText, DL_Links[i], 'Neuer Local File', [rfIgnoreCase, rfReplaceAll]);
      end;
    finally
      Htm.Free;
    end;
  finally
    DL_Links.Free;
  end;
end;
mit einem kleinen Html Parser den ich mal geschrieben hatte:


Ist aber Free Pascal, kann sein dass du für Delphi ein Paar Änderungen vornehmen musst
warfley is offline  
Old 04/03/2015, 19:44   #5
 
SwagBack's Avatar
 
elite*gold: 0
Join Date: Jan 2012
Posts: 355
Received Thanks: 42
Quote:
Originally Posted by warfley View Post
hier ist mal ein kleines Beispiel:
Code:
procedure TForm1.Button1Click(Sender: TObject);

  procedure CheckCSS(CSS: string; lst: TStringList);
  begin
    //Parse CSS here
  end;

  procedure CheckForLocalFiles(tag: PHtmlTag; lst: TStringList);
  var
    i: integer;
  begin
    if Assigned(lst) then
    begin
      if tag^.TagType = 'style' then
        CheckCSS(tag^.Content, lst)
      else if tag^.TagType = 'link' then
      begin
        for i := 0 to tag^.Propertys.Count - 1 do
        begin
          if PTagProperty(tag^.Propertys[i])^.Name = 'href' then
            if AnsiEndsText('.css', PTagProperty(tag^.Propertys[i])^.Value) then
            begin
              lst.Add(PTagProperty(tag^.Propertys[i])^.Value);
            end;
        end;
      end
      else
      begin
        for i := 0 to tag^.Propertys.Count - 1 do
        begin
          if PTagProperty(tag^.Propertys[i])^.Name = 'style' then
            CheckCSS(PTagProperty(tag^.Propertys[i])^.Value, lst)
          else if PTagProperty(tag^.Propertys[i])^.Name = 'src' then
            lst.Add(PTagProperty(tag^.Propertys[i])^.Value);
        end;
      end;
      for i := 0 to tag^.SubTags.Count - 1 do
        CheckForLocalFiles(PHtmlTag(tag^.SubTags[i]), lst);
    end;
  end;

var
  DL_Links: TStringList;
  Htm: THtmlFile;
  htmText: string;
  i: integer;
begin
  DL_Links := TStringList.Create;
  try
    htmText := IdHTTP1.Get('Link');
    Htm := THtmlFile.Create;
    try
      Htm.LoadHtmlFromString(htmText);
      CheckForLocalFiles(Htm.Tags, DL_Links);
      // Hier Dateien runterladen und ggf seperat parsen (css dateien)

      for i:=0 to DL_Links.Count-1 do
      begin
        htmText:=StringReplace(htmText, DL_Links[i], 'Neuer Local File', [rfIgnoreCase, rfReplaceAll]);
      end;
    finally
      Htm.Free;
    end;
  finally
    DL_Links.Free;
  end;
end;
mit einem kleinen Html Parser den ich mal geschrieben hatte:


Ist aber Free Pascal, kann sein dass du für Delphi ein Paar Änderungen vornehmen musst
danke vielmals
SwagBack is offline  
Reply


Similar Threads Similar Threads
[FIRST-RELEASE]HTML Log Datei
01/21/2015 - Metin2 PServer Guides & Strategies - 12 Replies
Hallo Dudes und Dudines, da ich eine längere Zeit kein Netz hatte und mir langweilig war habe ich angefangen eine neue Log Datei zu erstellen. Dabei war es mir wichtig das jeder ohne iwelche Programme die Datei lesen kann. Deswegen kam mir der Gedanke eine HTML Log Datei zu erstellen die jeder einfach im Browser öffnen kann um sie zu lesen. Vorteile - Jeder kann die Datei einfach lesen - Datum mit Jahres angabe - Einfache Datei struktur - Modernes Design
[Biete] HTML/CSS/JS/DELPHI Coding
10/25/2013 - Coders Trading - 0 Replies
Ich biete euch hier meine Arbeit an in: HTML/CSS/JS für eure Homepage oder/und Delphi für Programme Auch Designes für die Page/Programme sind machbar.
C# vs VB vs JAVA vs AUTO IT vs HTML vs PHO vs C++ vs Delphi ?
02/22/2013 - .NET Languages - 11 Replies
C# vs VB vs JAVA vs AUTO IT vs HTML vs PHO vs C++ vs Delphi ? hi everyone , i'm going to take this summer programmers lessons and i'm wondering wich one is the best language ???? what i want from programation ?? i want to be able to create little programmes and bots like ( pbdobot (it's writed in C# i think = PBDO-Bot for the Browsergame DarkOrbit ) or crack some tools :)
[Joomla][HTML] modul in einer html datei verlinken?
11/11/2011 - Web Development - 1 Replies
ich hab vorher im joomla forum schon ein thread geöffnet aber da antwortet mir niemand und ich ich langsam keine gedult mehr.. will heute noch weiter probieren und so. ---------------------------------------- Bei den Modulen gibt es ein leeres, wo man ein editor hat. Ist es möglich eine verlinkung zum modul in der html zu machen? Hier ein beispiel vom aufbau meiner website: Vorstellung wie die website ungefähr sein soll, wo ich welche div container gemacht habe, wie das ganze zur zeit...



All times are GMT +2. The time now is 21:31.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.