1 2 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| uses StrUtils, IdHTTP;
procedure GetLinksInHTMLDoc(URL: String; Links: TStrings);
var
HTTP: TIdHTTP;
Content, Link: String;
Position: Integer;
BeginPos: 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