0

I have a problem I have no idea how I can extract multiple links from html source code

html code are in Memo1 and links are extracted to memo2 ..

I use this function to extract links between 2 tangs or between 2 strings.

Function ExtractBetweenTags(Const Line, TagI, TagF: string): string;
var
  i, f : integer;
begin
  result := '';
  i := Pos(TagI, Line);
  f := Pos(TagF, Copy(Line, i+length(TagI), MAXINT));
  if (i > 0) and (f > 0) then
    Result:= Copy(Line, i+length(TagI), f-1);
end;

This gives only 1 link .. so how I can get all links I have tried many times but no luck :/

BenMorel
  • 34,448
  • 50
  • 182
  • 322
beingbad
  • 99
  • 1
  • 6
  • Look at the Delphi documentation for `PosEx`, which allows you to set a starting position for the next search. – Ken White Oct 09 '13 at 16:43
  • 4
    Use an html parser http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – David Heffernan Oct 09 '13 at 16:52
  • @David Agree with you in general, but you provided link to question with huge history and it is hard to find anything usefull there :) I put link to one lib i know as answer. – Andrei Galatyn Oct 09 '13 at 17:23
  • Maybe this can help: [HTML Tag Parsing](http://stackoverflow.com/questions/14348346/html-tag-parsing/14349613) – kobik Oct 10 '13 at 09:55

1 Answers1

2

An HTML parser is the only real solution for such task. You can find free one here:

http://www.yunqa.de/delphi/doku.php/products/tidy/history

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
Andrei Galatyn
  • 3,322
  • 2
  • 24
  • 38