求Delphi中提取网页源代码的例子

2024-12-27 22:44:12
推荐回答(1个)
回答1:

1.用idhttp

const
URL = 'http://www.qq.com';
begin
memo1.lines.text := idhttp1.get(URL);
end;

2.用webbrowser

//只获取到内的源码
const
URL = 'http://www.qq.com';
begin
webbrowser1.Navigate(URL);
while WebBrowser1.Busy do
Application.ProcessMessages;
memo1.lines.Text := WebBrowser1.OleObject.document.documentElement;
end;

//获取全部源码
uses ActiveX;
const
URL = 'http://www.qq.com';
var
ms: TMemoryStream;
begin
WebBrowser1.Navigate(URL);
while WebBrowser1.Busy do
Application.ProcessMessages;
ms := TMemoryStream.Create;
try
(WebBrowser1.Document as IPersistStreamInit).Save(TStreamAdapter.Create(ms), True);
ms.Position := 0;
Memo1.Lines.LoadFromStream(ms);
finally
FreeAndNil(ms);
end;
end;