Модератор: Модераторы
unit Unit1;
{$mode objfpc}{$H+}
interface
uses activex,comobj, variants, mshtml,
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var doc:variant;
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
doc:IHTMLDocument2; disp:DispHTMLDocument; v:variant;
el:IHTMLElementCollection;
itm:IHTMLElement;
i:integer;
begin
//http://www.webdelphi.ru/2010/05/mshtml-v-delphi-analiz-ssylok-na-stranice/
disp:=CoHTMLDocument.Create;
doc:=IHTMLDocument2(disp);
V:=VarArrayCreate([0,0],varVariant);
V[0]:='<html><body><a href="123">123</a><a href="123">123</a><br></body></html>';
Doc.write(PSafeArray(TVarData(v).VArray));
el:=IHTMLElementCollection(doc.body.all);
Caption:=IntToStr(el.Get_length);
for i:=0 to el.Get_length-1 do begin
itm:=IHTMLElement(el.item(i,0));
Caption:=itm.tagName;
end;
doc:=nil;
end;
end.
itm:=IDispatch(el.item(i,0)) as IHTMLElement;
unit Unit1;
{$mode objfpc}{$H+}
interface
uses activex,comobj, variants, mshtml,
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var doc:variant;
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
doc:IHTMLDocument2; disp:DispHTMLDocument; v:variant;
el:IHTMLElementCollection;
itm:IHTMLElement;
i:integer;p:pointer;
begin
disp:=CoHTMLDocument.Create;
doc:=IHTMLDocument2(disp);
V:=VarArrayCreate([0,0],varVariant);
V[0]:='<html><body><a href="123">123</a><a href="123">123</a><br></body></html>';
Doc.write(PSafeArray(TVarData(v).VArray));
Doc.close;
el:=IHTMLElementCollection(doc.body.all);
Caption:=IntToStr(el.Get_length);
for i:=0 to el.Get_length-1 do begin
p:=nil;
if el.item(i,0).QueryInterface(IID_IHTMLElement,p)=S_OK then begin
Caption:=IntToStr(integer(p));
itm:=IHTMLElement(p);
ListBox1.Items.Append(itm.tagName+' '+itm.innerHTML);
end;
end;
doc:=nil;
end;
end.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 233