uses ActiveX, ComObj;
//...
function GetHtml(const WebBrowser:TWebBrowser): string;//此函数原作者卢小海
const
BufSize = $10000;
var
Size: Int64;
Stream: IStream;
hHTMLText: HGLOBAL;
psi: IPersistStreamInit;
begin
if not Assigned(WebBrowser.Document) then Exit;
OleCheck(WebBrowser.Document.QueryInterface(IPersistStreamInit, psi));
try
hHTMLText := GlobalAlloc(GPTR, BufSize);
if 0 = hHTMLText then RaiseLastWin32Error;
OleCheck(CreateStreamOnHGlobal(hHTMLText,True, Stream));
try
OleCheck(psi.Save(Stream, False));
Size := StrLen(PChar(hHTMLText));
SetLength(Result, Size);
CopyMemory(PChar(Result), Pointer(hHTMLText),Size);
finally
Stream := nil;
end;
finally
psi := nil;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
HtmF:Textfile;
begin
memo1.Text:=gethtml(WebBrowser1);
assignfile(HtmF,'c:\result.htm');
rewrite(HtmF);
writeln(HtmF,memo1.text);
closefile(HtmF);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
webbrowser1.Navigate('http://www.google.com');
end;
------------引自 大富翁。
借助 webbrower 控件。
webbrower.nagivate('your url')