function CreateDocument(
const markup:
string): IHTMLDocument2;
var
doc: OleVariant;
begin
Result := CoHTMLDocument.Create
as IHTMLDocument2;
doc := Result;
doc.Open;
doc.
Write(markup);
doc.Close;
end;
function DecodeEntities(
const s:
string):
string;
var
doc: OleVariant;
begin
doc := CoHTMLDocument.Create;
doc.open;
doc.
Write(s);
doc.Close;
Result := doc.body.innerHtml;
end;
procedure ShowIt(doc: IHTMLDocument2; s: TStrings);
const
MARKER = '
showinfoalphabet(';
var
i, iLeft, iRight: Integer;
ec: IHTMLElementCollection;
e: IHTMLElement;
value:
string;
begin
ec := doc.all.tags('
a')
as IHTMLElementCollection;
for i := 0
to Pred(
ec.length)
do
begin
e :=
ec.item(i, null)
as IHTMLElement;
value := VarToStr(e.getAttribute('
onclick', 0));
if value = '
'
then Continue
else value := DecodeEntities(value);
iLeft := Pos(marker, Lowercase(value)) + Length(marker);
iRight := LastDelimiter('
)', value);
if iLeft > Length(marker)
then value := Copy(value, iLeft, iRight- iLeft)
else Continue;
s.Add(value);
end;
end;
// Test
procedure TDemoForm.ButtonClick(Sender: TObject);
var
doc: IHTMLDocument2;
csv, markup: TStrings;
fn:
string;
begin
fn := '
C:\Daten\DP\A.htm';
markup := TStringList.Create;
csv := TStringList.Create;
try
markup.LoadFromFile(fn);
doc := CreateDocument(markup.Text);
ShowIt(doc,
csv);
csv.SaveToFile(ChangeFileExt(fn, '
.csv'));
finally
markup.Free;
csv.Free;
end;
end;