| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 
 | procedure GetLinksInHTMLDoc(URL : string; Links : TStrings); 
var HTTP : TIdHTTP; 
    Content, Link : string; 
    Position : integer; 
begin 
  HTTP := TIdHTTP.Create(nil); 
  try 
    Links.Clear; 
    Content := HTTP.Get(URL); 
 
    Position := 0; 
    while True do 
    begin 
      Position := PosEx('href', Content, Position+1); 
      if Position = 0 then Break; 
      inc(Position, 4); 
      while (Position < Length(Content)) and (Content[Position] in [#0, #10, #13, ' ']) do inc(Position); 
      if Content[Position] <> '=' then Continue; 
      inc(Position); 
      while (Position < Length(Content)) and (Content[Position] in [#0, #10, #13, ' ']) do inc(Position); 
      if Content[Position] <> '"' then Continue; 
      inc(Position); 
      BeginPos := Position; 
      while (Position <= Length(Content)) and (Content[Position] <> '"') do inc(Position); 
 
      Link := Copy(Content, BeginPos, Position-BeginPos); 
      if (Link <> '') and (Links.IndexOf(Link) = -1) then 
        Links.Add(Link); 
    end; 
  finally 
    HTTP.Free; 
  end; 
end; | 
Partager