Jan
15
как вытянуть из html-файла список всех ссылок и картинок не используя WebBrowser
12:24unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ActiveX, ComObj, MSHTML;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
vHttp: OleVariant;
vContext: OleVariant;
vDocument: IHTMLDocument2;
vHtml: String;
vColl:IHTMLElementCollection;
i:integer;
begin
Screen.Cursor:=crHourGlass;
Button1.Enabled:=false;
vHttp := CreateOleObject('Microsoft.XMLHTTP'); { Requires IE5 }
vHttp.Open('GET', 'http://www.google.ru/', False, EmptyParam, EmptyParam);
vHttp.Send('');
vHtml := vHttp.responseText;
vDocument := CoHTMLDocument.Create as IHTMLDocument2;
vContext := VarArrayCreate([0, 0], varVariant);
vContext[0] := vHtml;
vDocument.Write(PSafeArray(TVarData(vContext).VArray));
vDocument.Close;
vDocument.all.tags('A').QueryInterface(IHTMLElementCollection,vColl);
ListBox1.Clear;
for i:=0 to vColl.length-1 do begin
ListBox1.Items.Add((vColl.item(i,EmptyParam) as IHTMLElement).innerText);
end;
Button1.Enabled:=true;
Screen.Cursor:=crDefault;
end;
end.