How do I parse links from a file?

This is a very common question and very, very simple with ATagParser.

The simplest way is to use the OnAttribute event and watch for the HREF attribute name and ParentTagHash. Drop an instance of ATagParser on a form.

Include in the Uses clause
HTML_Ex, HTML_Constants  
 
ComplexFilters settings
cfParseAttributes = True  
cfStripQuotes = True  
 
Elements settings
etAttribute = True  
etComplexTag = True  
 
 
Double click the OnAttribute event and add the following code:

procedure TForm1.ATagParserAttribute(Sender: TObject;
  Attribute: TAttributeElement; var Abort: Boolean);
var
  AttrID, TagID: Integer;
begin
   AttrID := HTML_Ex.FindAttributeID(Attribute.Hash);
   If Index = AID_HREF Then
   Begin
     TagID := HTML_Ex.FindTagID(Attribute.ParentTagHash);
     If TagID = TID_A Then
       // Attribute.Value holds the actual link

   End;
end;
 
It's just that simple.



Copyright 2000 - 2006 John E McTaggart - All rights reserved worldwide